Menu
After Effects Tutorials / Video Editing

How to Add an Expression in After Effects

expression in after effects

In the filmmaking industry, high-quality work and speed are of the essence. To achieve this, the software developers from Adobe made After Effects capable of helping us achieve this. Adding expressions in After Effects is one of the things that help speed up the workflow and also helps video editors and motion graphics artists create good-looking animations with no effort.

After Effects is one of the leading software in the filmmaking post-production industry. Many video editors and motion graphics artists make use of AE’s tools and expressions, to create beautiful works of art, animated videos, video ads, special video effects, and many more useful things.

What are After Effects Expressions?

coding

Expressions are chunks of code written in the Extendscript or Javascript language with the sole purpose of altering the After Effects layer properties. They can automate repetitive tasks and build flexible rigs.

When you write an expression on a property, you can start creating relationships between that property and other layers. Expression Controllers found in the Effects & Presets window can help you better control the expressions, by linking them to the numeric parameters.

Why use Expressions in After Effects

In order to extend your capabilities far past what is possible with keyframes alone, speed up your workflow, automate repetitive tasks, build flexible rigs, and create some specific type of animation, you must make use of expressions in After Effects. There are many types of expressions that can help you achieve creative and complex animations.

It is easy to start using expressions — each expression you will learn will become a time-saving and work-simplifying tool. The more you know, the faster you will become when working with After Effects.

Adding an Expression in After Effects

You can add expressions to any type of layer and to any type of layer property inside AE. Don’t get discouraged — the beauty of expressions is that you don’t need to be a master at coding or programming to start using them.

Some expressions are short and easy to use and understand, while other expressions are long and complicated. Even if they might seem complicated, pasting them inside their dedicated space should do the trick.

rotation expression in editing

To use expressions, you have to write/copy and paste them inside the dedicated space. Open the layer properties, hold “Alt”(PC) or “Option” (Mac), and click on the stopwatch of the property you want to apply the expression to.

In the timeline under the layer, a text box will appear and the numeric parameters will turn red. Here you will type or paste the expressions.

Easy Useful Expressions in After Effects

There are a lot of expressions we can talk about. Unfortunately, they tend to get complicated and hard to understand if you don’t have a good understanding of how After Effects works. For this reason, I will write about some easy, useful expressions I use all the time. At the end of the article, I attached a video that contains all the examples below.

Tip: To make the expressions work, just copy and paste them after you “Alt”(PC) or “Option” (Mac) click the stopwatch or type them in. Whatever values I will use in this article, you can change them to what works best for your project.

Wiggle Expression in After Effects

The Wiggle expression will force the given parameter to randomly wiggle within the set parameters.

For example – Wiggle(a,b), but you will use one with numeric values like this: wiggle(3,25).

Here “a” is the parameter that controls the speed of the wiggle and “b is the parameter that controls the amount to wiggle.

With this expression, you will wiggle on both dimensions at the same time. There will be times when you will need to wiggle only one dimension. To do so, use one of these expressions:

Wiggle only x (horizontal): org=value; temp=wiggle (3,25); [temp[0],org[1]];

Wiggle only Y (vertical): org=value; temp=wiggle (3,25); [org[0],temp[1]];

Time Expression in After Effects

The Time expression in After Effects returns the current time of the composition into seconds. The values it generates can then be used to animate a layer by connecting a property’s value to the expression.

Examples of time expressions and what they do:

time – returns a composition’s current time in seconds;

time.toFixed(2) – limits how many numbers are allowed after the decimal;

time*n – just like time but it multiplies the value it provides, “n” can be any number you want;

Inertial Bounce Expression in After Effects

Inertial Bounce expression is more complicated than the previous ones — you don’t have to understand the coding. To use the expression, make a normal 2 keyframes animation, copy and paste it into the dedicated space of that parameter and that is it.

If you use easy ease on one of the keyframes, the animation will change. This expression is perfect for the scale parameter — it will create a perfect bounce motion.

n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time){
}
}
if (n == 0){
t = 0;
}else{
t = time - key(n).time;
}
if (n > 0 && t < 1){
v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
amp = .05;
freq = 4.0;
decay = 8.0;
value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
value;
}

Bounce Back Expression in After Effects

Just like the Inertial Bounce expression, the Bounce Back expression is more complicated than the previous ones — you don’t have to understand the coding. To use the expression, make a normal 2 keyframes animation, copy and paste it into the dedicated space of that parameter and that is it.

If you use easy ease on one of the keyframes, the animation will change. This expression is perfect for the position parameter. It will create a perfect bounce motion. The difference is that this expression will create something like a rubber ball hitting a wall type of motion.

You can modify “e”, “g”, and “nMax” parameters as you want. You will notice the motion will change, so play with them and see for yourself what they do.

e = .7;
g = 5000;
nMax = 9;

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

These last 2 expressions were created by Dan Ebberts at motionscript.com.

expression in after effects

Now you know how to add expressions in After Effects, how to play with them, and some easy-to-use expressions that I use all the time. There’s much more to talk about expressions and how to use them, but I will let you guys discover more after you master the basics.

About Author

After spending 6 years in the post-production studio, Mihai decided to share his insights on video editing and computers.

No Comments

    Leave a Reply