Article
No items found.

How to Use the Time Expression in After Effects

by
Ryan Plummer

What is the Time Expression in After Effects?

The time expression in After Effects returns a composition's current time in seconds. You can write the time expression in After Effects by simply typing the word time;

The values generated by this expression can then be used to drive movement by connecting a property value to the expression.

After Effects counting seconds with the time expression

In the example above I rigged a text layer to preview the value generated by the time expression. As the composition is playing you see the seconds being counted in the composition panel through that rigged text layer. All I did was used a simple time expression to have After Effects generate those values.

time.toFixed(2);

Note: toFixed() limits how many numbers are allowed after the decimal

How Does the Time Expression Work in After Effects?

To help illustrate explain exactly what I mean, I want you to think about time in a new way. Try to think of time as the number it's producing and not as a time counter. When you can start to view time as a number that can be manipulated then you will start getting a better grasp on this expression.

For example, If I double the time expression using multiplication it would read 8 seconds within a 4 second composition time.

time*2;

A faster time readout using the time expression

To further drive it home i'll add the time expression to the rotation property. The rotation property will return 1 degree per 1 second.

Rotating one degree per second

For every second the composition runs the rotation will increase by one degree. But, that example is kinda boring and you may not be able to see much change very well. Let's speed things up a little!

A full rotation every second

Just look at that little line go! In the first example we get 1 degree for every second. So if we want to get a full rotation every second we need to know how many degrees are in 1 full rotation; which is 360 degrees.

time*360;

By multiplying the value time provides by 360 we are asking After Effects to speed up the process exponentially. It now is going to complete a 1 degree move 360 times within one second.

Examples of the Time Expression in After Effects

Now that you've wrapped your head around what time is doing, let's show you some practical examples you can start using in your workflow.

Rotate Multiple Layers

Here is an example of looping rotations at different speeds. Imagine if you had a bunch of gears that needed to rotate, or an astroid field that needed slight rotations for those cold heavy rocks.

I took the time expression and multiplied them by different amounts! As a bonus, I'd like to share a neat trick that I first learned from Parker Young's expression courses on Animoplex.

For rotation, multiply time by 360, which is one full rotation, and then divide it by the number of seconds you would like a full rotation to happen. Here's what that would look like in code:

// One full rotation every 2 seconds
time*(360/2);

Time Travel, Sorta...

One really useful way to harness the time expression is creating delayed movements. We can actually ask After Effects to look forwards and backwards in time. For this I'm going to introduce a new expression valueAtTime();.

The bottom layer is delayed from the top layer

For this example I asked After Effects to look at the x position of another layer, and then told it to delay by half a second. Amazingly, the code is super simple, and by using the index of a layer you can duplicate over and over again with each layer having it's own delaying. Note: The index expression in After Effects pulls a value based on the layer's order in the timeline.

thisComp.layer(index+1).transform.xPosition.valueAtTime(time - .5)

Does that expression seem confusing? Zack Lovatt is a fan of breaking down the various parts of code into common language so it's easier to understand. Here is how he would break down valueAtTime:

var halfASecond = 0.5;
var now = time;
var halfASecondAgo = now - halfASecond;

valueAtTime(halfASecondAgo);

In a nutshell, valueAtTime is an expression that tells After Effects to pull a value from a property (scale, position, slider, etc.) for a declared time.

MAKE IT RAIN!

If you want to try out something fun, I'm handing off a simple project file to you. Inside you'll find a money counting rig tied to time. I've placed a slider effect in there that allows you to increase how fast the money value is increasing! If you'd like to know how I added the dollar sign to the money counter, I've left some notes in my expression.

{{lead-magnet}}

It's Time for More!

I hope you see how awesome the time expression can be. There are a lot of use cases outside of what I went over in this article!

If you want to learn more about using expressions in After Effects we have a ton of other great expression content here on School of Motion. Here are a few of our favorite tutorials:

Also, if you want to master expressions in After Effects, we have the course for you! Check out Expression Session taught by Zack Lovatt & Nol Honig!

The All-Access discount is SOLD OUT, but you can still get 25% off all individual courses! We’ve been quietly rolling out our new All-Access program, where you can get every course we make for one low price. It’s a crazy good deal even without this sale. But until Wednesday 12/4, you can get it for 25% off. For this sale we are opening up 100 spots. After those sell out, you’ll have to wait at least a few months until we open more. Don’t sleep on this deal. We expect it to sell out fast.

ENROLL NOW!

Acidbite ➔

50% off everything

ActionVFX ➔

30% off all plans and credit packs - starts 11/26

Adobe ➔

50% off all apps and plans through 11/29

aescripts ➔

25% off everything through 12/6

Affinity ➔

50% off all products

Battleaxe ➔

30% off from 11/29-12/7

Boom Library ➔

30% off Boom One, their 48,000+ file audio library

BorisFX ➔

25% off everything, 11/25-12/1

Cavalry ➔

33% off pro subscriptions (11/29 - 12/4)

FXFactory ➔

25% off with code BLACKFRIDAY until 12/3

Goodboyninja ➔

20% off everything

Happy Editing ➔

50% off with code BLACKFRIDAY

Huion ➔

Up to 50% off affordable, high-quality pen display tablets

Insydium ➔

50% off through 12/4

JangaFX ➔

30% off an indie annual license

Kitbash 3D ➔

$200 off Cargo Pro, their entire library

Knights of the Editing Table ➔

Up to 20% off Premiere Pro Extensions

Maxon ➔

25% off Maxon One, ZBrush, & Redshift - Annual Subscriptions (11/29 - 12/8)

Mode Designs ➔

Deals on premium keyboards and accessories

Motion Array ➔

10% off the Everything plan

Motion Hatch ➔

Perfect Your Pricing Toolkit - 50% off (11/29 - 12/2)

MotionVFX ➔

30% off Design/CineStudio, and PPro Resolve packs with code: BW30

Rocket Lasso ➔

50% off all plug-ins (11/29 - 12/2)

Rokoko ➔

45% off the indie creator bundle with code: RKK_SchoolOfMotion (revenue must be under $100K a year)

Shapefest ➔

80% off a Shapefest Pro annual subscription for life (11/29 - 12/2)

The Pixel Lab ➔

30% off everything

Toolfarm ➔

Various plugins and tools on sale

True Grit Texture ➔

50-70% off (starts Wednesday, runs for about a week)

Vincent Schwenk ➔

50% discount with code RENDERSALE

Wacom ➔

Up to $120 off new tablets + deals on refurbished items

Success! Check your email (including spam folder) for your download link. If you haven't yet confirmed your email with us, you'll need to do that one time.
Oops! Something went wrong while submitting the form.
Featured
No items found.
No items found.