Top 6 Common After Effects Expressions Editors Use (+6 New Options)

After Effects 25/05/2021 7 min read

When you are creating animated elements and flourishes for your project, you can spend hours trying to perfect your keyframing. Whether you want to create an impactful overshoot bounce effect or a simple repeater, After Effects Expressions can save you so much time creating the visual assets.

After Effects Expressions are short pieces of code that tell After Effects how to treat your keyframed animation, adding Expressions can look complicated, especially when you look at the coding used. However, once you know how to add the Expression Function to your layers, all you need to do is paste in the codes below. We have a more detailed explanation in our post How To Use Templates, Presets, Scripts, & Expressions.

You can download the After Effects project that contains all of the examples below, including the bird animation here.

Part 1: Adding an Expression Effect

Expressions can be added to a range of transform effects to add cool animation, which might take you hours to create from scratch. Adding Expressions is always done in the same way; it is the code that differs depending on what you want to achieve. The first part is to learn how to add an Expression effect to your layer.

  1. Add your shape/image to your timeline.
  2. Create 2 keyframes for your chosen transformation; in our example, we are using Scale.
  3. Select the Transform option you have keyframed from the timeline, and go to the Animation menu. We are selecting the Scale option, as that is what we have keyframed. You can add expressions to multiple Transform settings, but you should do each one in turn.
  4. Select Add Expression from the menu and a box will appear on the timeline.
  5. Paste your expression into the box, we are using the Bounce expression.
  6. You can finely tune the expression by changing the values in the code; play around with each to see what works for you.

Part 2: Top Useful 6 After Effects Expressions 

There are loads of different Expressions you can use in your After Effects projects, we’ve put together this handy list.

1. Wiggle

The Wiggle expression is one of the few that can be used without keyframes. Simply add the expression to any Transform property, and watch your shape start to wiggle. If you do choose to add keyframes, it will wiggle between them.

wiggle(1,50);

2. Wiggle One Dimension

There are 2 Wiggle One Dimension expressions, one for your X-axis, and one for the Y. Unlike the first wiggle expression on this list, the one dimension effect allows you to control the direction of your wiggle.

Y-Axis / Vertical

org=value;

temp=wiggle (5,50);

[org[0],temp[1]];

X-Axis / Horizontal

org=value;

temp=wiggle (5,50);

[temp[0],org[1]];

3. Bounce

The Bounce expression is super helpful when you want to create a bouncing overshoot to your animated elements. The Bounce is ideal for adding to Scale, Rotation, and Position settings, and when used together, it can create a remarkable Ease out.

amp = .1;

freq = 2.0;

decay = 2.0;

n = 0;

if (numKeys > 0){

n = nearestKey(time).index;

if (key(n).time > time){

n–;

}}

if (n == 0){ t = 0;

}else{

t = time – key(n).time;

}

if (n > 0 && t < 1){

v = velocityAtTime(key(n).time – thisComp.frameDuration/10);

value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);

}else{value}

4. Inertia Bounce

Inertia Bounce is an excellent expression to have handy when you want to create the effect of anything dropping in to shot with a slight bounce. You can adjust the code to create the impression of a more substantial or bouncy asset.

n = 0;

if (numKeys > 0){

n = nearestKey(time).index;

if (key(n).time > time){

n–;

}

}

if (n == 0){

t = 0;

}else{

t = time – key(n).time;

}

if (n > 0){

v = velocityAtTime(key(n).time – thisComp.frameDuration/10);

amp = .05;

freq = 4.0;

decay = 2.0;

value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);

}else{

value;

}

5. Loop (Cycle)

If you have ever tried to create a looping/repeating animation without using expressions, you will be familiar with the painstaking process of copying and pasting your keyframes. The Loop expression solves the issue, creating a seamless animation loop to your shapes.

loopOut(“cycle”);

6. Squash And Stretch

Squash and stretch is another expression that is awesome with or without additional keyframing. Ideal for animated flourishes and graphical elements, this expression will squash and stretch your shapes in a fun, jiggling way.

maxDev = 13; // max deviation in pixels

spd = 30; //speed of oscillation

decay = 1.0; //how fast it slows down

t = time – inPoint;

x = scale[0] + maxDev*Math.sin(spd*t)/Math.exp(decay*t);

y = scale[0]*scale[1]/x;

[x,y]

Part 3: 6 Additional After Effects Expressions You Should Use 

1. Motion Tail

Motion Tail is a neat expression that saves you from duplicating and distributing repeating shape layers. Use this code to create a cool repeating tail to your elements. This expression as a couple of extra steps:

  1. Paste the below code to your Position properties.
  2. Select the layer in the timeline.
  3. Press Cmd+D or Ctrl+D to duplicate the layer as many times as you want it to repeat.

thisComp.layer(thisLayer, – 1).position.valueAtTime(time – .1)

2. Time

The Time expression allows you to set the speed of the animation without changing your keyframes. This expression is super handy when you want to adjust the speed of several elements.

vtime*10

3. Timecode/Timer

Add this expression to the Source Text property of any text layer to create a simple to edit timer. Great for adding timecodes to your project, or countdown clocks for event videos.

//Define time values

var hour = Math.floor((time/60)/60);

var min = Math.floor(time/60);

var sec = Math.floor(time);

var mili = Math.floor(time*60);

// Cleaning up the values

if (mili > 59){ mili = mili – sec*60; }

if (mili < 10){ mili = “0” + mili; } if (sec > 59){ sec = sec – min*60; }

if (sec < 10){ sec = “0” + sec; } if (min >= 59){ min = min – hour*60; }

if (min < 10){ min = “0” + min; }

// no hour cleanup

if (hour < 10){ hour = “0” + hour; }

//Output

hour + ‘ : ‘ + min + ‘ : ‘ + sec + ‘ : ‘ + mili;

4. Elastic

Elastic is a fun expression to use on both flourishes and text elements. Using your last Position keyframe, the expression swings your assets round as if on elastic.

var p = 0.6;

var a = 140;

var s = 1.70158;

function outElastic(t, b, c, d, a, p) {

if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;

if (!a || a < Math.abs(c)) { a=c; var s=p/4; } else var s = p/(2*Math.PI) * Math.asin (c/a); return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b); } function easeAndWizz() { var n = 0; if (numKeys > 0) {

n = nearestKey(time).index;

if (key(n).time > time) { n– }

}

try {

var key1 = key(n);

var key2 = key(n+1);

} catch(e) {

return null;

}

var dim = 1; 

try {

key(1)[1];

dim = 2;

key(1)[2];

dim = 3;

} catch(e) {}

t = time – key1.time;

d = key2.time – key1.time;

sX = key1[0];

eX = key2[0] – key1[0];

if (dim >= 2) {

sY = key1[1];

eY = key2[1] – key1[1];

if (dim >= 3) {

sZ = key1[2];

eZ = key2[2] – key1[2];

}

}

if ((time < key1.time) || (time > key2.time)) {

return value;

} else {

val1 =  outElastic(t, sX, eX, d, a, p, s);

switch (dim) {

case 1:

    return val1;

    break;

case 2:

    val2 = outElastic(t, sY, eY, d, a, p, s);

    return [val1, val2];

    break;

case 3:

    val2 = outElastic(t, sY, eY, d, a, p, s);

    val3 = outElastic(t, sZ, eZ, d, a, p, s);

    return [val1, val2, val3];

    break;

default:

    return null;

}

}

}

(easeAndWizz() || value);

5. Automatic Fade

The Automatic Fade might be the handiest expression on our list. When you are working with several elements, adding a fade in/out to each layer can be massively time-consuming. Instead, use the Automatic Fade transition to fade in and out at the beginning and end of each layer.

transition = 20;       

if (marker.numKeys<2){

tSecs = transition / ( 1 / thisComp.frameDuration); 

linear(time, inPoint, inPoint + tSecs, 0, 100)

 – linear(time, outPoint – tSecs, outPoint, 0, 100)

}else{

linear(time, inPoint, marker.key(1).time, 0, 100) 

– linear(time, marker.key(2).time, outPoint, 0, 100)

}

6. Undulation

The Undulation expression is similar to a wiggle but in a 3D environment. If you want to make your shapes look as though they are rocking back and forth toward the camera, this could be the one for you.

xAmp = 40; 

xFreq = .3; 

xSpeed = 150; 

wl = xSpeed/xFreq; 

phaseOffset = ((position[0]%wl)/wl)*2*Math.PI;

y = xAmp*Math.sin(2*Math.PI*xFreq*time + phaseOffset);

value + [0,y]

Part 4: How to Use the Wiggle Expressions Together on a Project

The great thing about expressions is you can use them on multiple transform properties at the same time, allowing you to animate a range of motion in your elements quickly. Here we are using the wiggle expressions together to create a unique animation.

  1. Create your shape layer on your timeline.
  2. Select the Position property, add the Wiggle Expression.
  3. Adjust the settings so you are happy with the Position Wiggle amount.
  4. Repeat these steps with the Rotation and Scale properties.
  5. Adjust the settings until you are happy with the movement of your objects.
  6. If you have multiple elements you want to add the same effect, try adding the Expressions to a Null layer and lassoing your layers to the Null.

Expressions look complicated, and it can be frustrating when something in the code is wrong. Fortunately, there are a ton of helpful walkthroughs and tutorials available online. No matter what you are animating, there is an Expression that can help save you the time and frustration of keyframing individual elements. Now you know how to use Expression, why not bookmark this article to keep the code handy.