Bounce

elasticity = 0.6;

gravity = 5000;

bounces = 7;

// Ignore everything below here

n = 0;

if (numKeys > 0){

n = nearestKey(time).index;

if (key(n).time > time) n--;

}

if (n > 0){

t = time - key(n).time;

v = -velocityAtTime(key(n).time - .001)*elasticity;

l = length(v);

if (value instanceof Array){

u = (l > 0) ? normalize(v) : [0,0,0];

}else{

u = (v < 0) ? -1 : 1;

}

tCur = 0;

segDur = 2*l/gravity;

tNext = segDur;

nb = 1;

while (tNext < t && nb <= bounces){

l *= elasticity;

segDur *= elasticity;

tCur = tNext;

tNext += segDur;

nb++

}

if(nb <= bounces){

delta = t - tCur;

value + u*delta*(l - gravity*delta/2);

}else{

value

}

}else

value

 

The bounce expression is very similar to the inertia expression, but it reacts as if it’s bouncing off a surface - no overshoot.

This expression only works on properties with two keyframes; a starting state and a finishing state.

Copy and paste the below expression into any property with two keyframes. The closer the keyframes are to one-another, then the greater the bounce will be, so keep this in mind. If you are seeing no bounce at all, it may be because your keyframes are too far apart and not enough momentum has been built between the two keyframes for the expression (which uses maths) to create a bounce.

All you need to do is copy and paste the above expression onto any property with two keyframes. Once the timeline reaches the second keyframe (its stopping point) the expression calculates how much bounce to generate, with help from the values of three top lines, which you are able to adjust.

elasticity

The elasticity is the bounciness of the layer. The higher the number, the bouncier the object will become. For example, if I input the value 0.8 then the ball bounces much higher each time.

But if I was to put a low value, like 0.3, then the ball becomes less bouncy and gives the appearance of being a much heavier object.

The example above only has identical bounce expressions, with only the elasticity being altered slightly.

From left to right the elasticity = 0.4, 0.5 & 0.6.

gravity

The gravity is self explanatory - its the gravity of the imaginary scene. If you increase this number it create heavier gravity - meaning the object will not bounce as high. If this value is decreased then the ball will bounce much higher due to less gravity.

You can almost ignore this value as I find 5000 is a very natural gravity simulation and the height of bounces can simply be adjust using the previously mentioned elasticity.

The example above only has identical bounce expressions, with only the gravity being altered.

From left to right the gravity = 4000, 5000 & 6000.

bounces

This is the number of bounces you want your layer to have. This is necessary to prevent the expression from continuously trying to calculate the next bounce even when the layer is stationary. Feel free to adjust this number but be aware, if the number is too low and the layer is still bouncing after the number of allowed bounces is reached, it will automatically jump to its finished state.

The example above only has identical bounce expressions, with only the number of bounces being chaning.

From left to right the bounces = 1, 2 & 3.

This is another expression where you need to just dive in! Copy and paste the expression onto one of your layers with two keyframes and adjust the top three lines as mentioned, and see what happens!

Previous
Previous

Delay