Back to Blog Index

How to Use the Bounce Expression in After Effects

Quickly give your layers organic movement with the Bounce Expression in After Effects.

What if you dropped a basketball and it didn't bounce? You'd probably think something was off, right? Well, the same is true in animation. Motion Design is all about the communication of ideas, and replicating movements found in the real world is an essential part of telling a compelling story. This is why it's so important to give your animations weight and mass like objects found in the real world. And this my friend is where the bounce expression comes into play...

If you're looking for a quick way to add a bounce to any layer, then this After Effects bounce expression is just for you. At first glance it can seem very daunting, and honestly it's super complex. But, don't let the complexity of it scare you away! I'm going to break down what you need to know so that you know how to use the bounce expression in your After Effects projects.

Credit to Dan Ebberts, a coding wizard, who created this bounce expression.

Dive into real-time 3D with our Unreal Engine beginner's course by Jonathan Winbush. Master importing assets, world-building, animation, and cinematic sequences to create stunning 3D renders in no time! Perfect for motion designers ready to level up.

Explore this Course

Unlock the secrets of character design in this dynamic course! Explore shape language, anatomy rules, and motifs to craft animation-ready characters. Gain drawing tips, hacks, and Procreate mastery (or any drawing app). Ideal for artists seeking to elevate their craft.

Explore this Course

Elevate your freelance motion design career with our guide to client success. Master a repeatable method for finding, contacting, and landing clients. Learn to identify prospects, nurture leads, and develop a thriving freelance philosophy amidst chaos.

Explore this Course

Rev up your editing skills with After Effects! Learn to use it for everyday needs and craft dynamic templates (Mogrts) for smarter teamwork. You'll master creating animated graphics, removing unwanted elements, tracking graphics, and making customizable templates.

Explore this Course

Stand out with Demo Reel Dash! Learn to spotlight your best work and market your unique brand of magic. By the end, you'll have a brand new demo reel and a custom campaign to showcase yourself to an audience aligned with your career goals.

Explore this Course

Illuminate your 3D skills with Lights, Camera, Render! Dive deep into advanced Cinema 4D techniques with David Ariew. Master core cinematography skills, gain valuable assets, and learn tools and best practices to create stunning work that wows clients.

Explore this Course

Master After Effects at your own pace with Jake Bartlett's beginner course. Perfect for video editors, you'll learn to create stylish animated graphics, remove unwanted elements, and track graphics into shots. By the end, you'll be equipped for everyday AE needs and more.

Explore this Course

Revolutionize your Premiere workflow with customizable AE templates! Master creating dynamic Motion Graphics Templates (Mogrts) in After Effects to speed up your team's work. By the end, you'll craft easily-customizable templates for seamless use in Premiere Pro.

Explore this Course
Bounce Expression Project File
Grab this FREE bounce expression project!
Your download is in your inbox!!!
Check your email (spam, too) for the download link!
Please check the spam folder if you don't see the message within a minute or two. Google likes to hide your downloads, sometimes.
Oops! Something went wrong while submitting the form.

The After Effects Bounce Expression

The bounce expression is great because it only takes two keyframes to create a bounce. After Effects will interpolate the velocity of your layers' movement to help determine how the bounce will work. The math that goes into making this bounce expression is pretty darn nerdy.

Feel free to copy and paste this After Effects Bounce Expression below. Don't worry, you don't have to know how this entire expression works to use it.

e = .7; //elasticity
g = 5000; //gravity
nMax = 9; //number of bounces allowed

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)*e;
 vl = length(v);
 if (value instanceof Array){
   vu = (vl > 0) ? normalize(v) : [0,0,0];
}else{
   vu = (v < 0) ? -1 : 1;
 }
 tCur = 0;
 segDur = 2*vl/g;
 tNext = segDur;
 nb = 1; // number of bounces
 while (tNext < t && nb <= nMax){
   vl *= e;
   segDur *= e;
   tCur = tNext;
   tNext += segDur;
   nb++
 }
 if(nb <= nMax){
   delta = t - tCur;
   value +  vu*delta*(vl - g*delta/2);
 }else{
   value
 }
}else
 value

Don't let that scary expression monster scare you away. I'm going to show you the parts of the expression that you'll need to worry about and what they do to affect the bounce. So in the end we'll only be focusing on the top three lines. It's not that scary...

Small Bounce Snippet.png

CONTROLLING THE BOUNCE EXPRESSION

When working with the bounce expression in After Effects there are three different portions that you will want to make changes to:

  • variable e - controls the elasticity of the bounce
  • variable g - controls the gravity acting on your object
  • variable nMax - the maximum amount of bounces that are allowed

What Does Elasticity Mean? 

For elasticity, imagine you have a bungee chord attached to your object. The lower the number you give for e the more stiff the bounce will look. If you're looking for a bounce that feels loose, just raise this value.

The example below bounces better than a Mega Bounce XTR which is the Rolls Royce of bouncy balls, but I personally prefer like a Wham-O Superball because it has a similar coefficient of restitution for a better price... but I digress.

High elasticity values and a low amount of gravity

What is Gravity in the Bounce Expression? 

In the bounce expression gravity works just how you would think gravity should work, the higher the gravity the heavier the object will feel. If you increase the gravity value you will make the object seem heavier. Once your object completes its initial contact it will start to finish the remainder of your bounce quicker and quicker.

Low elastic and High Gravity

The Pros and Cons of the Bounce Expression

The bounce expression is an amazing example of just how powerful expressions can be in After Effects. But, you will quickly find out that this expression is a one-trick pony. It will be very useful for bringing in layers that just need a simple bounce, but it's no substitute for a solid understanding of how to create a bounce. In fact, the 'ball bouncing' exercise is probably the most popular animation exercise used for training aspiring animators.

If you want to learn more about organic movements in After Effects, make sure to check out our tutorial covering the graph editor in After Effects. Joey goes over how to start implementing organic bounce movements in your workflow and how you can obtain a bounce without using expressions!

BEYOND THE BOUNCE

I hope that you now feel equipped to use the bounce expression in your After Effects projects. If you'd like to challenge yourself to learn more about After Effects, animation and expressions check out Expression Session!