After Effects Expressions gives you the power of creating animations that are impossible or hard to create manually. One such expression helps in creating trails of a moving object.

There are couple of basic approaches to creating trails in After Effects. In this example, we’ll use “valueAtTime” method to retrieve the position value of the leader layer at a previous time.

Lets take a look at the expression:

trail-gif

delay = 5; //number of frames to delay

d = delay*thisComp.frameDuration*(index - 1);
thisComp.layer(1).position.valueAtTime(time - d)

In the above code or expression, the first line just sets the number of frames that we want each layer to be delayed from the previous layer. The second line calculates the time delay of each layer based on its position in the layer stack. In this example, the delay for Layer 1 will be zero as it the “leader”, the delay for Layer 2 will be 5 frames, for Layer 3 it will be 10 frames and so on. The last line retrieves the position value of the lead layer at the current time minus the layer’s delay.

Adding a Fade

We can add interest to the animation by adding another expression to the opacity that will exponentially fade the layer’s opacity depending on how far down it is in the layer stack.

Here’s the opacity expression:

trail-fade-gif

opacityFactor = .75;

Math.pow(opacityFactor,index - 1)*100