Expression-based motion trail in After Effects

I was recently working on a motion graphics piece that involved numerous shape and text layers.  One of the effects I was going for was to have part of a logo flying around with a motion trail behind it.  Unfortunately, the Echo filter built into After Effects didn’t quite achieve the look I was going for: while it would duplicate the graphic element multiple times and fade off a little bit with adjustments to the decay rate, I was also wanting the motion trail to shrink in size.  It also introduced number of issues with 3D layer elements in After Effects, so suffice it to say that I needed another solution.  I’ve been dabbling with expressions in After Effects and after some tinkering around, I was able to use them to get the exact look I wanted as well as built in controls to adjust the effect very easily.

This tutorial has two sections: First, we’ll build the basic effect with the Echo filter, then we’ll build it again with the added functions and controls through expressions.

Start with a new, empty composition.  Draw out an ellipse at the center of the composition, then move it to the left.  Set a few animation keys to have it go from left to right, putting ease on both frames.  (Fig. A) To have this behavior mirror and repeat, we’re going use a very simple expression.  Alt+Click on the stop watch by the Position attribute and type in:


Fig. A

After entering this expression, the circle should move from left to right, then right to left, and repeat until the end of your composition (Fig. B).

Fig. B

Now to apply the echo filter, located in Effects -> Time -> Echo.  I’ve adjusted some of the settings to get some opacity falloff.  (Fig C)  These settings are pretty self explanatory, though one thing to keep in mind is to keep the Echo Time very very small and set to a negative; if you set it as a positive, it’ll look forward in the timeline for the position of the circle and draw a motion trail based on that (which could also be a useful look, depending on what you need).  However, you’ll notice that the repeated instances of the circle are very hard-edged.  Correct this by adding a Fast Blur effect and setting the amount as needed to get a smooth look.   (Fig. D)

Fig. C

Fig. D

At this point, we have the basic look: a soft motion trail that decays over time.  For some situations this may work just fine, but in addition to wanting the instances to decrease in scale, this may cause issues with 3D effects if elements are flying in and out of the composition.  While I’m not entirely sure what is happening, my best guess is that the Echo effect takes a 2D snapshot of the layer and applies the effect based on that.  Instead, let’s have the motion trail directly reference the layer transform data with expressions.

Delete the Echo effect on the circle layer.  Create a new null layer, move it to the very top, and rename it “trailControl”.  Apply three Slider Controls (Effect -> Expression Control -> Slider Control) to the layer and set them as shown in Figure E.  (Click on a slider control and hit Enter to rename it; the naming conventions have to match this tutorial exactly if you want to follow along.)  Right now this null object isn’t doing anything, but we’ve built in some controls so that it can later influence the look of the motion trail.

Fig. E

Next, duplicate the circle layer, then Alt+Click on the stopwatch by its Position attribute and then regular-click on the stopwatch again to delete all animation keys.  If you scrub the timeline, the circle on layer 2 will move but the one on layer 3 will remain stationary.  To make the third layer act as a motion trail, Alt+Click on the stopwatch a third time and enter in the following expression:

timeOffset = thisComp.layer(“trailControl”).effect(“trailPositionTimeOffset”)(“Slider”);


If your After Effects throws up an error, make sure the name of the circle layer matches what’s in the expression.  In my case, the layer was called ‘Circle’; yours may be different, so make sure they match.  Once everything is set up properly, when you click on the third layer and scrub through the timeline you’ll see that it’s ever-so-slightly behind the second layer.  (Fig. F) The effect will become more apparent if you duplicate the third layer multiple times. (Fig. G)  With the expression we made earlier, we’ve told After Effects to take the position of Circle (the circle we initially drew) at a fraction of a second earlier (as defined by the trailPositionTimeOffset slider on the trailControls layer) and apply that to the current layer.  This offset cascades downward (this is what the ‘index – 2’ is for; it uses the current layer’s number but subtracts the two layers above it from the calculation) as you duplicate the layer; in this case, each subsequent duplicate of this layer will be another 0.01 seconds behind.

Fig. F

Fig. G

Confused yet?  No?  Good, let’s move on, as we need to program in more expressions for opacity and scale.

Delete all layers in this comp except for the first three (the trailControl, Circle, and one of the duplicates [in my case Circle 2]).  Open up the Opacity for your duplicate circle, Alt+Click on the stopwatch, and apply the following expression:


Math.pow(opacityOffset,index – 2)*100

This expression uses exponential math (Math.pow) to determine the opacity of the layer.  First it references the number programmed into the trailOpacityOffset slider on the trailControl layer, then raises that to the power of the current layer number (minus two, to ignore the two layers above it in the calculation).  For this first duplicate, it’s 0.85 to the first power, which is 0.85.  Duplicate it once and the next copy’s opacity is 0.85 x 0.85, the next is 0.85 x 0.85 x 0.85, and so forth.  (Fig. H)

Fig. H

Lastly, we need to make a cascading expression for the trail’s scale.  Delete all layers except the control, the initial circle, and the duplicate of the initial circle.  Alt+Click on the scale attribute of the duplicate and enter this expression:


[Math.pow(scaleOffset,index - 2)*100,Math.pow(scaleOffset,index - 2)*100]

This one’s a little different because Scale consists of two values: X and Y.  This is why the second line of the expression is in brackets and has the same entry repeated with a comma between them: the first instance is applied to the X axis, the latter to the Y (ie: [x,y]).  Were we working on a 3D layer, we’d have to copy and paste the entry for a third time to account for Z (i.e. [x,y,z]).  Duplicate this layer multiple times and you should notice the subsequent duplicates becoming smaller.  (Fig. I)

Fig. I

From here, you can adjust the look of the motion trail in a number of ways with the trailControl layer.  You can adjust how far back in time the trail extends by increasing or decreasing the trailPositionTimeOffset, adjust how much the trail shrinks with the trailScaleOffset, and adjust how quickly it fades away with the trailOpacityOffset.  Note that you might also need to make or decrease the number of duplicate layers in the comp: if the opacity of the bottommost layer is extremely low you might not even see it, or if it’s too high then you need more duplicates as the trail may appear to simply stop instead of fade.  Either way, play with it until you get the look you want.

That’s the end of this tutorial.  There are many additional levels of control you can build into this motion trail rig once you get the hang of how the math and syntax work, so I highly recommend you read up on expressions as they’re extremely powerful and can simultaenously speed up and improve the quality of your work. Thanks for reading!

Click here to return to the blog
Click here to go to the front page

Tags: , , ,

Leave a Reply