Activity › Forums › Adobe After Effects Expressions › Expression for rolling Billiard (Pool) Ball
-
Expression for rolling Billiard (Pool) Ball
Posted by Rutger on August 11, 2007 at 5:53 pmI am trying to get the effect of a rolling Billiard (Pool) ball on a pool table. I made the look of say an eight ball as a flat image and wrapped it around a sphere using the CC sphere effect. Easy so far…
Now, I want it to roll over a table (top view). This works nicely, since I linked the Y-rotation to the position of the ball as follows:
360*transform.position[0]/(2*Math.PI*effect(“CC Sphere”)(“Radius”))
This works nicely when the ball simply rolls left to right on screen. However, when I start to angle the ball, it starts to ‘skid’ or ‘slip’.
I thought I would have an easy workaround by adding an expression for the X-rotation as follows:360*transform.position[1]/(2*Math.PI*effect(“CC Sphere”)(“Radius”))
but it still does not look right (I tried to put a negative sign in front of the last expression with no success either.)
What am I doing wrong?
Rutger
Rutger replied 18 years, 8 months ago 3 Members · 10 Replies -
10 Replies
-
Rutger
August 11, 2007 at 9:36 pmDan,
A Top view for now is all I want, since in another animation I already did a “3D view” of a pool ball. This was obviously using the same expressions that you suggested to make Andrew Kramer’s Earth Tutorial look three-dimensional, which can be applied to any spherical object of course. Now, correct me if I am wrong, but once you apply your expressions to the rotation, you lose the ability to dictate the rotation of the object. For example can you spin around a sphere, while the sphere is rotating in opposing direction?
Anyway, for this animation, I am not interested in a fully 3D experience (unless it can be easily done). I have a top-down view of a number of billiard balls that need to hit one another and roll convincingly over the table. Since the balls have numbers on them any slipping or skidding is going to look fake.
What I am looking for is expression for the rotation of the ball based upon the position, this assumes of course that the ball is played without spin, no slipping etc. So if postion at the ball at time 0 = [x0,y0] and at time t = [xt,yt] what expressions can I write for rotation as a funtion of time in both x and y direction.
I was thinking myself along the line of comparing its current x and y coordinate to the respective values at time zero, and using this difference to steer the rotation, but I ran into errors when using valueAtTime command.
Any ideas are greatly appreciated.
Rutger
-
Dan Ebberts
August 11, 2007 at 11:40 pmI think it can be done, but the only way I can think of to do it will require some pretty hairy 3D rotation matrix math to calculate the angles for rotation around an arbitrary axis. Then you might have to translate the results from AE’s coordinate system to Sphere’s. I think it would be a lot of work.
Maybe somebody will chime in with a better idea.
Dan
-
Kevin Camp
August 13, 2007 at 3:46 pmi was able to link you expression to a null with auto orientation turned on, so the null would orient to direction that was moving, and that seemed to correct the mult-dimentional rotation issue.
i linked the y rot of cc sphere to the y pos of the null:
-360 * thisComp.layer(“Null 1”).transform.position[1] / (2 * Math.PI * effect(“CC Sphere”)(“Radius”))
then i just parented the cc sphere layer to the null so it would follow the nulls movement and orientation.
Kevin Camp
Designer – KCPQ, KMYQ & KRCW -
Rutger
August 14, 2007 at 1:28 amHello Moldyboot,
I tried your suggestion, but unfortunately I still get weird skidding effects.
Now, what expression do you use for the x rotation of the CC sphere effect? or are you only using an expression for y-rotation? Since I am looking for a rotation in two directions simulatenously. Again, when the ball simply rolls horizontally or vertically everything is fine. As soon as I use angles, the rotation starts to behave unnaturally.
So, for example, using your animation, can you put a ball in the left top corner of the screen and have it roll naturally to the lower right corner of the screen (without rotating the comp obviously….), if so I would like to know, because that is what I am trying to accomplish.
Let me know and thanks for your help…
Rutger
-
Kevin Camp
August 14, 2007 at 2:05 pmsorry, i didn’t fully test this… there does seem to be a problem using only the x pos as the variable for rotation when the diagonals are extreme, also the rotation reverses if the x pos value is descending.
i have an idea to fix this, i’ll get back to you soon.
can you work with only two postion key frames?
Kevin Camp
Designer – KCPQ, KMYQ & KRCW -
Kevin Camp
August 14, 2007 at 3:16 pmok,
you don’t need a null (you didn’t earlier, that was my oversight).enable the auto orient function for the sphere layer. paste this into the y rotation property of cc sphere:
pos = thisLayer.transform.position;
if (pos.numKeys < 2){ value; }else{ t = pos.key(2).time - pos.key(1).time; rate = length(pos.key(1).value, pos.key(2).value) / t; if (time - pos.key(1).time > 0){
if (time – pos.key(2).time >= 0){
360 * rate * t / (2 * Math.PI * effect(“CC Sphere”)(“Radius”));
}else{
360 * rate * (time – t) / (2 * Math.PI * effect(“CC Sphere”)(“Radius”));
}
}else{
value;
}
}the expression looks at the length or distance that the layer moves rather than just the x or y component, this helped to keep the ‘roll’ consistent regardless of angle. it also compares the current time to the time between the position key frames to allow the ‘roll’ to start and stop with the position.
this is a work around.. it doesn’t actually produce a realistic mult-dimensional roll, it just allows the direction and speed of the ‘roll’ to seem natural. and currently it won’t work coorectly with non-linear position keyframes.
Kevin Camp
Designer – KCPQ, KMYQ & KRCW -
Kevin Camp
August 14, 2007 at 7:10 pmhere’s a better version, still seems a bit wordy, but now keyframe interpolation is accounted for. i also fixed an initial ‘slip’ in the rotation, so now rotation begins at 0. and i added the ‘value +’ to allow setting of an initial start angle for the ball (ie. 30 degrees + the roll simulation).
pos = thisLayer.transform.position;
if (pos.numKeys < 2){ value; }else{ t = pos.key(2).time - pos.key(1).time; startPos = pos.key(1).value; endPos = pos.key(2).value; d1 = length(startPos, endPos) / t; d2 = length(startPos, pos.valueAtTime(time)) / (time - pos.key(1).time); if (time - pos.key(1).time > 0){
if (time – pos.key(2).time >= 0){
value + (360 * d1 * t / (2 * Math.PI * effect(“CC Sphere”)(“Radius”)));
}else{
value + (360 * d2 * (time – pos.key(1).time) / (2 * Math.PI * effect(“CC Sphere”)(“Radius”)));
}
}else{
value;
}
}anybody know how to get a position vector to degrees??? then we could link the light direction to the layer position. if i have a little time tomorrow, i’ll look into it…
Kevin Camp
Designer – KCPQ, KMYQ & KRCW -
Kevin Camp
August 14, 2007 at 9:08 pmok, i think this will work for the light direction:
pos = thisLayer.transform.position;
d = sub(pos.key(2).value, pos.key(1).value);
value – radiansToDegrees(Math.atan2(d[1], d[0]))this would have been easier if i had paid more attention in trig… and if i had a book on java and ae expressions.
dan, when are you writing a book?
Kevin Camp
Designer – KCPQ, KMYQ & KRCW -
Rutger
August 15, 2007 at 3:18 amKevin,
I really appreciate your efforts, sorry I could not respond earlier…
Anyway, I tried your new suggestions and I see a lot of improvement, although there seems to be a slight amount of spin when I play with the initial x or z-rotation for instance (certain settings are clearly better than others). But the rotation is much better now, and I think I can select it such that artifacts are barely visible.
Initially, I thought it still did not work, but that was because I had actually turned my Sphere layer into a 3D layer. Reason for this is that I want to create a number of shadows (from multiple spotlights around the table). What I am planning to do is create multiple invisible discs (one for each light) that only cast shadows. Each individual disk would face (orient towards) one light. All these discs would be parented to the sphere layer, so as the ball moves, the shadows move along. This way I hope to achieve 4 or 5 different shadows that clearly look like artificial lighting.
Anyway, thanks a lot for your help. I am not sure that it is the ‘true solution’ to the problem, but it seems that I can work with this.
Thanks again,
Rutger
Reply to this Discussion! Login or Sign Up