ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Re: not the "usual" bouncing-ball question...

COW Forums : Adobe After Effects Expressions

FAQ   •   VIEW ALL   •   ADD A NEW POST   •   PRINT
Respond to this post   •   Return to posts index   •   Read entire thread


Filip Vandueren
Re: not the "usual" bouncing-ball question...
on Aug 13, 2009 at 6:15:05 pm

I have an expression that adds the arc movement inbetween keyframes.

I took your example move and stabilized it, then I made a circle shape and animated the position with hold-keyframes for every impact on the foor or body. Just 2D positions:



Then I added this expression to the position keyframes:


if (numKeys>1) {
kick=100; // strength of each kick

// get the previous & next keyframes
nk=nearestKey(time);
prev_k=(nk.time >time && nk.index>1) ? key(nk.index-1) : nk;
next_k=key(Math.min(prev_k.index +1,numKeys));

// force linear interpolation
x_pos=linear(time,prev_k.time,next_k.time,prev_k.value,next_k.value);

// calculate a Sine to simulate bounce
// (I find that sine^0.85 more accurately, though not perfectly, models gravity)
ang=linear(time,prev_k.time,next_k.time,0,Math.PI);
y_bounce=Math.pow(Math.sin(ang),0.85)*kick.valueAtTime(prev_k.time)*[0,1];

// base the height of the bounce on the amount of time between keyframes.
duration=next_k.time-prev_k.time;

x_pos-y_bounce*duration;

} else {
value
}

Result:


Already there is some convincing bouncing going on, but we need to vary the strength of the kick, as you can see near the end, sometimes it needs a real yank.

I put an expression control slider named "kick" on the ball layer
and pickwhipped to change the 2nd line to:

kick=effect("kick")("Slider"); // strength of each kick

Now I keyframed the Kick slider, unstabilized, and I wound up with this, which is a somewhat accurate simulation. Discrepancies lie in spin on the bal, Z-depth movement, and air-resistance (and of course the stabilize wasn't that great to begin with)

But that's all irrelevant, since you're starting from an animated character.



As I said, this just animates an arch between position keyframes. If you want the ball to bounce away after your character did his last kick, you'll have to animate some further contact points on the floor and decrease the kick slider untill zero.

This expression is set up for 2D, but it's quite easy to adjust to 3D positions should need be.






Posts IndexRead Thread 


Current Message Thread:





© 2020 CreativeCOW.net All Rights Reserved
[TOP]