After Effects Expression Basics — Wiggle

Expressions in Adobe After Effects are an invaluable tool that can save hours during the motion design process, and can help create animations that are almost impossible to do with just keyframes. They are however a bit intimidating to learn at first, mainly because they involve working with code.

If you are a beginner it’s important to just start with basic expressions that are just a few lines long, that way you can really understand what is happening under the hood and start to build up to more complicated use cases.

The first expression that I personally learned was the wiggle expression, and it’s a really great one to start with. To apply a basic wiggle expression to your layer, you’ll need to Opt+Click (Mac) or Alt+Click (Win) on the stopwatch of a layer property. In this example we’ll be applying the wiggle to the position property of a shape layer.

After option clicking on the layer, the property values will turn red, and the expression editor should appear in the timeline. In the expression editor, enter the following code:

wiggle(5, 50)

What this does is tell After Effects that you want to wiggle (or randomly move) this layer 5 times per second, with a maximum movement of 50 pixels in any direction. Try playing with different values here and see how it effects your layer.

This works because wiggle() is a JavaScript function built in to the AE Expression Engine. You don’t need to learn JavaScript to understand basic expressions, you just need to understand this:

The wiggle function takes in arguments, in this case the arguments were 5 and 50, then it does some math based on those arguments and returns a value for each frame. The layer property with the expression applied to it is then assigned that returned value at each frame.

With that in mind, we can start doing some more advanced wiggle expressions. For example, what if you just wanted to wiggle the square in the x axis? Luckily there is a simple way to do that, while still keeping everything on one line with the following expression:

[wiggle(5, 150)[0], value[1]]

The position property can be broken down into [x,y] values, so in this case the x = the return value of the wiggle expression, and y = the original unchanged y axis value. Try reversing the order and see how it effects your layer.

Wiggle is of course not just limited to the position property, experiment by applying the wiggle expression to things like scale and rotation as well. One common use for the wiggle expression is to simulate a shaking camera by
Pre-composing a scene, wiggling the values on that entire composition, and scaling it up to hide any gaps on the edges of the frame.

I only showed expressions with two arguments for the beginner section of the tutorial, as most of the time that is all you’ll need, however the full syntax of the wiggle expression is as follows:

wiggle(freq, amp, octaves=1, amp_mult=0.5, t=time)

Here is an explanation of each parameter according to official Adobe Documentation:

freq value is the frequency in wiggles per second.amp value is the amplitude in units of the property to which it is applied.octaves is the number of octaves of noise to add together. This value controls how much detail is in the wiggle. Make this value higher than the default of 1 to include higher frequencies or lower to include amplitude harmonics in the wiggle.amp_mult is the amount that amp is multiplied by for each octave. This value controls how fast the harmonics drop off. The default is 0.5; make it closer to 1 to have the harmonics added at the same amplitude as the base frequency, or closer to 0 to add in less detail.t is the base start time. This value defaults to the current time. Use this parameter if you want the output to be a wiggle of the property value sampled at a different time.

The base start time is easy to understand and experiment with when applying the wiggle expression, but the octaves and amp_mult options are a bit harder to think about, so I create a graph to help visualize how they effect the resulting values of the expression.

To do this I create a layer which moves from left to right across the entire screen, duplicated it three times using the same seed value for the wiggle, and limited the wiggle to the y axis. I then baked the expressions to keyframes, and overlapped the resulting motion paths.

Hopefully you’ve learned a lot about the wiggle expression from this blog post, and you’ll feel comfortable trying it out on your own projects!

Software Developer and Video/Post Production Professional. Recent graduate of Flatiron School.