Ease and Wizz has a preset for “bounce”, adapted from Robert Penner’s easing equations. It’s useful for basic simulations, but it doesn’t give much flexibility when it comes time to customise it. Fortunately, most everyone on Earth has plugged their computer into The Internet, so a solution is never far away.

Dan Ebberts gives a great introduction to After Effects expressions on his site, motionworks.com, including a slew of articles on physical simulations. I’ve taken the example that Dan provides for a basic bounce, modified it a little, and made it into a preset for you (hey, it’s that time of year):

Ebberts bounce.ffx.zip

There are sliders to adjust amplitude, decay, and frequency. By tweaking these you’ll be able to achieve a variety of effects. I recommend reading Dan’s original post about this expression too. If you don’t have time to peruse the original post, at least check out what Dan has to say about choosing the frequency:

Note that you need to choose your frequency carefully to sell this effect. For example, at 30 frames per second, a frequency of 2.0 will cause the first bounce to occur half way between frames 3 and 4. So it will look like the ball never quite hits the “floor”. To have it occur exactly at frame 3, you would need to change your frequency to 2.5, and to make it occur at frame 4, you’d change the frequency to 1.875.

Now: having quoted Dan’s sage words, I’m going to encourage you to screw it all up by tweening the frequency. In real life, frequency increases as the amplitude gets smaller (think of a ping pong ball, and the way the bouncing speeds up). By tweening the frequency (say, starting at 1 and ending at 2), I find I’m able to get it to look a little more convincing.

Note that this expression does not use keyframes – it only uses the values defined on the sliders.

If you’re still with me, here’s what the expression looks like:

``````try {
freq = effect("bounce - frequency")("Slider"); //oscillations per second
amplitude =  effect("bounce - amplitude")("Slider");
decay =  effect("bounce - decay")("Slider");
} catch(e) {
freq = 1;
amplitude = 500;
decay = 1;
}

posCos = Math.abs(Math.cos(freq*time*2*Math.PI));
y = amplitude*posCos/Math.exp(decay*time);
value - y``````

This differs from Dan’s version in that it only works on one dimension, i.e. you’ll need to use “Separate Dimensions” in order to use it (but the preset will handle that for you). That way it’s easy to have it bounce on the y axis, and animate the x position independently.

You’ll see it also uses the `try … catch` construct. This is for when you paste an expression onto a layer that doesn’t have the correct Expression Sliders in place. If you don’t catch the error, you can potentially have dozens of annoying dialog boxes pop up telling you that it can’t find a certain effect. I’ve been caught out enough times that I like to build this safety net into my expressions. I am nothing if not a failed trapeze artist.