Expression Shorts – Wiggle Only One Direction


The most popular After Effects expression that nearly EVERYONE uses or at the very least, has used once in their life, has a nack for confusing some users when they only want it to effect just one direction. This solution, has been around for a long time and I figured I’d add my explanation to the mix as well.

If you are one of the rare few that are unfamiliar with the wiggle() expression, then you will be learning a fun piece of code that can come in handy quite often. After watching the video, scroll down for the code breakdown to better understand what does what.


x = transform.position[0];
y = transform.position[1];
w = wiggle(3, 200);

[w[0], y];

wiggle() – First I’m gonna start off with a brief explanation of what wiggle() is for those who may not know. wiggle() is a stock expression that basically creates chaotic “wiggling” movement. The two* primary arguments that you need to input are, the Frequency (how fast to wiggle) and Amplitude (how much to wiggle). Frequency will determine how many times per second to wiggle and Amplitude will determine the maximum amount to vary from the current property value. For example, if you had an X position value of 100 and you wanted to wiggle that value fives times a second and have that wiggle move no more than 200 pixels. You would write…

wiggle(5, 200);

This would produce an X position value somewhere between -100 and +300. Some layer properties do not allow negative values or values above 100%, like the Opacity property. If you applied the same expression to Opacity, you would have a value range between 0 and +100. So while the expression may be producing a value near +300, it gets capped off at +100. Just something to be aware of.

* Frequency and Amplitude are the two most common arguments, but there are actually three more arguments as well. Octaves, Amplitude Multiplier, and Time. Like so…

wiggle(freq, amp, octaves = 1, amp_mult = .5, t = time);

Octaves and Amplitude Multiplier can give you a little more control over the resulting values.

1) x = transform.position[0];
2) y = transform.position[1];
3) w = wiggle(3, 200);
4) [w[0], y];

Line 1: We have assigned the current X position value to a variable called x. This allows us to still control the layer’s X position via the traditional slider if we choose to not have the wiggle on this axis.
x = transform.position[0];

Line 2: We have assigned the current Y position value to a variable called y. This allows us to still control the layer’s Y position via the traditional slider if we choose to not have the wiggle on this axis.
y = transform.position[1];

Line 3: We assign wiggle(3, 200) to a variable called w. This assignment allows us to use the wiggle on any axis we choose by simply using this variable. Multiple wiggle variations are possible as well and could be made by simply duplicating this line and calling the variable a unique name. So say you wanted different frequencies and amplitudes. You could type…
wSlowFar = wiggle(1, 600);
wMediumShort = wiggle(3, 18);
wFastShort = wiggle(10, 8);
You could then mix and match them.

Line 4: This is our final result that gets output. We create an array for our values using brackets, [ ], then we place the variables we want in the array. For a 2D layer, the Position property has two items in the array, X axis and Y axis. 3D layers have three items, X axis, Y axis, and Z axis. Arrays start at 0, so the index number for X, Y and Z would be 0, 1 and 2. Variable w is on the X axis so we need to tell After Effects that we only want the X informtion, so we type w[0], because this is the X output value from our wiggle expression. If we wanted the Y value, we type w[1], and for Z we type w[2]. The y variable used here is our variable that we assigned to the current Y position value, so it will not wiggle.
[w[0], y];

I want to thank everyone for all the kind emails regarding the Expression Shorts series. I’m glad they have been helpful and for some, timely in their arrival. I’ve got many more episodes made and ready for release in the coming weeks. Some neat stuff coming up.

Share Our Article

David Torno is a Visual Effects professional based in Los Angeles, California. His work over the years has included commercials, feature films, music videos, and multimedia projects. During his free time, David enjoys expanding his…

Leave a Reply

1 Comment threads
1 Thread replies
Most reacted comment
Hottest comment thread
2 Comment authors
David TornoTimothy Susanto Recent comment authors
newest oldest most voted
Notify of
Timothy Susanto
Timothy Susanto

how do you do it the other direction