Our Top 5 After Effects Expressions

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

We use After Effects for all of our video graphics. It’s a very versatile tool that allows anyone with a passing understanding of Photoshop or Illustrator to jump in and start animating, and one of the things that makes it so versatile is the ability to apply expressions.

Expressions are bits of code that are written in JavaScript and can be applied to any parameter that you can keyframe. If you’re unfamiliar, a keyframe in animation is a point in the timeline where a property changes. For example, animating the scale of a graphic from 0 to 100 takes two keyframes, one set to 0% and one set to 100%. The program automatically changes the scale between the keyframes, so you don’t have to do it automatically. In traditional animation, this was called tweening, but we just call it awesome.

 

Expressions can be used to modify animations in the tweening process or to set values of properties based on other factors. We use expressions all the time and here are our top five:

Ebberts Facing Away Expression

It’s actually called “Layer Invisible When Facing Away From Camera”, but we call it the Ebberts Facing Away Expression. It was written by Dan Ebberts, an After Effects Expression/Scripting zen guru maestro, who always has an answer to any question on the After Effects boards. This expression gets applied to the Opacity property:

 

toCompVec([0, 0, 1])[2] > 0 ? value : 0

 

Basically, when applied to the opacity property, the expression makes the layer invisible when it rotates away from the camera. We typically use this to change text on screen, like this:

  1. Take two layers and parent one to the other.
  2. Apply the expression to the opacity layer of each.
  3. Set the initial y-rotation property of the child layer to 180.

When you rotate the parent layer, the child layer rotates with it and replaces the parent’s text when the parent goes past 90º in either direction.

Ebberts Facing Away Expression

Ebberts Decay Expression

Another expression by the brilliant Dan Ebberts, this one slows an animation down gradually, overshooting, going backwards, overshooting a little less, going backwards a little less, until coming to a rest, like a pendulum. This is all done with trigonometry, and if you don’t understand, don’t worry, we don’t either! This can be applied to position, rotation or scale properties:
freq = 3;
decay = 5;

n = 0;
if (numKeys > 0){
  n = nearestKey(time).index;
  if (key(n).time > time) { n-- };
}
if (n > 0){
  t = time - key(n).time;
  amp = velocityAtTime(key(n).time - .001);
  w = freq*Math.PI*2;
  value + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}
else { value }
The only values you need to worry about are the frequency (the freq variable) and the decay. The higher the frequency, the faster it swings. The lower the decay, the longer it takes to come to a rest. It seems counterintuitive, but that’s math for you. I’m sure there’s a reasonable explanation. For a more in-depth look at the way this expression works, and for bouncing expressions as well, visit Dan Ebberts’ Motionscript site. While you’re there, take a look at all the other expressions – it’s a wealth of information!
Ebberts Decay Expression

Ease & Wizz Expressions

While these are technically not expressions you write or paste in (although if you feel you must, you can), Ease & Wizz is a script available from aescripts.com that applies easing equations to keyframes with a click of a button. It was written by Ian Haigh, who adapted easing expressions developed by a bloke named Robert Penner.

In a nutshell, easing does what it sounds like – it eases in and out of keyframe values. Imagine driving a car. When you’re going 0 to 60 in four seconds, you don’t actually increase your speed by 15 mph each second. That would be crazy! You’d end up with whiplash. Instead, your speed ramps up until you reach 60mph. The same for when you’re braking. It’s not like there’s a steel cable attached to the frame of your car and stops you dead completely at the end. Again, whiplash! You ease into the stop when you press the brakes. So Ease & Wizz does the same thing, but it applies calculus equations to the tweening process, and lets you ramp up and down gradually, or really quickly, between keyframes. If you want to have a really dynamic movement, use the Expo setting.

Ease & Wizz

Scale Expression

This expression is an oldie but a goodie – not sure where it came from, but I believe it was developed by the After Effects team. This gets applied to the scale property of a layer:
cam = thisComp.activeCamera;  
distance = length(sub(position, cam.toWorld([0,0,0])));  
scale * distance / cam.zoom;
It maintains the scale of a layer based on the distance from the camera. So, when applied to the scale property of a 3D layer, you can move the layer to and from the camera, and it will appear to stay the same size. It’s super helpful when positioning layers in a 3D scene and you want to achieve a parallax effect, where the layers seem to move at different speeds, based on how far away they are from the camera. The only problem with this expression is if you move the camera towards the layer, it maintains its size, so it can ruin the effect. Still, you can apply the expression, make a note of the proper scale for the distance, disable the expression, and then change the scale manually. It won’t be mathematically perfect, but it’ll be close enough for horseshoes. Also, hand grenades.
Scale Expression

Blink Expression

This is one we developed for character eye blinking, although it’s pretty simple. You take two layers – one a closed eye layer, and one an open eye. You apply this expression to the closed eye layer:
(parent.opacity == 100) ? 0 : 100;
And then apply this to the open eye layer:
x = random(18, 100);
(x < 20) ? 0 : 100;
Basically, it sets a random number from 18 to 100 on the open eye layer, and if the generated number is less than 20, it turns the open eye off and the closed eye layer on. This way, by manipulating the numbers, you can randomly make the eye blink with a somewhat natural appearance, and not have to set the keyframes manually. If you want to learn more about applying expressions check out Adobe’s page on the subject, and please share your favorites with us in the comments below.
Blink Expression

More To Explore

Creative

Our Top 5 After Effects Expressions

We use After Effects for all of our video graphics. It’s a very versatile tool that allows anyone with a passing understanding of Photoshop or

Contact Us

  • This field is for validation purposes and should be left unchanged.
Photo of Current360 Associate Creative Director Robert Womack

Rob Womack

If there’s anyone who can honestly say, “Been there, done that,” it’s Rob. After traveling the world for seven years in his 20’s, Rob went to LA and started working in film production. Then it was off to New York, where he learned how to program, which eventually brought him back home to Louisville to build websites. At Current360, Rob heads up our in-house production studio, creating all things digital for our clients — videos, commercials, radio spots, and a lot more. 

When he’s at home, Rob likes to create things like homemade kombucha and music.