Skip to main content

Taking the time to use Expression Scripts in Adobe After Effects will allow you to create fantastic animation sequences in your project with just a few lines of code. Typically, these types of animations created with traditional key frames would take far longer to produce, so if you have been put off in the past by using ‘code’ in your After Effects project, it is certainly something that we recommend you take the time to check out for yourself!

There are a few Expressions that I often come back to in After Effects, and in this short new series of blog posts dedicated to Adobe After Effects, I am going to share with you the scripts that I often and use and explain how they work:

How And Where To Add Expression Scripting

First, let’s quickly recap how and where we can add our scripts. Expression scripts can be placed on any layer property for which a keyframe value can be set. This is usually indicated by the ‘Time Vary Stopwatch’ icon displayed next to the editable value in the main timeline.

To open the scripting area for the value, Alt+Left Click (Option+Left Click for Mac) on the stopwatch icon. Now you will be presented with the text field area where you can write your script. Thankfully, we can also paste pre-written scripts into this box too! Which is great as many times we can reuse such lines of codes and simply edit the values within to create the results we are looking for, such as with our bounce expression, which we will apply to our layer’s Scale value:

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);
amp = .12;
freq = 6;
decay = 7.0;
value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
value;
}

The main values that we want to edit in order to alter the behaviour of the bouncing movement are as follows:

Amplitude – This controls the strength of the initial bounce animation

Frequency – This controls how rapidly the bounce animation will reverberate after the initial bounce

Decay – This controls how quickly the bounce animation reverberation will last

All that remains for us to do now is apply a keyframe animation taking the scale value of any layer from a starting position (usually 0) up to full size (100). See the results that this expression script does to this process with our four tradesmen animation sequence below:

No Scripting

With Scripting

Chris Hodgson

Chris Hodgson

Chris Hodgson is an award-winning Digital learning Solutions Developer and Director of Discover eLearning Ltd. He supports SMEs and large firms through the process of integrating eLearning into their organisation. Chris has over 10 years experience working in Higher Education, Independent Training Provider Sector and Charity Sector learning and development.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.