Skip to content
A small code panel linked by a red curve to a smooth sine wave plotted across a graph, with two red keyframe dots on the curve
Back to blogtips

7 After Effects Expressions You Must Know (With Copy-Paste Code)

ANFX 2017-10-15 5 min read

Seven copy-paste After Effects expressions — wiggle, loopOut, time, bounce, valueAtTime and more — with the exact code and when to use each one.

You’re hand-keyframing a camera shake, frame by frame, and it still looks mechanical. Or you’ve copy-pasted the same four keyframes thirty times to fake a loop, and now the client wants it 10% faster. Expressions — small snippets of JavaScript attached to a property — solve both problems in one line each.

Alt-click (Option-click on Mac) the stopwatch on any property to open the expression editor, paste the code, and press Enter. Here are the seven expressions that cover 90% of everyday motion graphics work.

1. wiggle() — Instant Organic Motion

The most-used expression in After Effects. On Position:

wiggle(3, 25)

The first number is frequency (wiggles per second), the second is amplitude (pixels). wiggle(3, 25) gives you handheld camera shake; wiggle(1, 5) gives you a gentle idle drift; wiggle(12, 60) on a text layer reads as violent jitter — a core ingredient of the look covered in how to create a glitch effect in After Effects. It works on almost any property: Rotation, Opacity, Scale, even effect sliders.

2. loopOut() — Never Copy-Paste Keyframes Again

Set a few keyframes once, then make them repeat forever. On any keyframed property:

loopOut("cycle")

"cycle" repeats the keyframes from the start. Three variants matter:

  • loopOut("pingpong") — plays forward, then backward, then forward. Perfect for pendulums and pulsing glows.
  • loopOut("offset") — repeats the motion but continues from the last value instead of snapping back. A walk cycle keeps walking forward.
  • loopOut("continue") — no repeat; the property keeps moving at its final velocity. Great for objects that should drift off-screen.

If you’re building looping background animations, pair this with the splice-point checks in the seamless video loops guide — a cycled expression loops perfectly by construction.

Keyframe-Free Motion: time and Math.sin()

3. time — endless rotation

On Rotation:

time * 100

time is the current comp time in seconds, so this spins the layer 100 degrees per second, forever, with no keyframes to manage. Negative values reverse direction. Multiply by a slider (Effect > Expression Controls > Slider Control) and you can retime the spin without touching the expression.

4. Math.sin() — smooth repeating oscillation

Where wiggle() is random, a sine wave is perfectly regular. On Position, this bobs a layer up and down 20 pixels:

value + [0, Math.sin(time * 2 * Math.PI) * 20]

Use it for floating icons, breathing logos, and hovering UI elements — anywhere randomness would look wrong but stillness looks dead.

5. Inertial Bounce — Overshoot That Settles

Linear keyframes stop dead. Real objects overshoot and settle. Paste this on any keyframed property (Position, Scale, Rotation) and every keyframe gets a decaying elastic bounce:

amp = 0.1;
freq = 2.0;
decay = 5.0;
n = 0;
if (numKeys > 0){
  n = nearestKey(time).index;
  if (key(n).time > time){ n--; }
}
if (n == 0){ t = 0; } else { t = time - key(n).time; }
if (n > 0 && t < 1){
  v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
  value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
} else {
  value;
}

Raise amp for a bigger overshoot, raise decay to settle faster. This one expression replaces the six or eight easing keyframes you’d otherwise sculpt by hand.

Linking Layers: valueAtTime() and linear()

6. valueAtTime() — the delayed follower

Make one layer trail another by sampling the leader’s position a fraction of a second in the past. On the follower’s Position:

thisComp.layer("Leader").transform.position.valueAtTime(time - 0.2)

Duplicate the follower a few times with increasing delays (0.2, 0.4, 0.6) and you get an instant trailing-echo effect — follow-through animation without a single extra keyframe.

7. linear() — remap any value range

linear() converts one range of numbers into another. On Opacity, this fades a layer in over its first second without keyframes:

linear(time, 0, 1, 0, 100)

Read it as: as time goes from 0 to 1, output goes from 0 to 100. It becomes genuinely powerful when the input is something else — a slider, an audio level, another layer’s rotation — which is exactly how audio-reactive rigs work.

When an Expression Is the Wrong Tool

Expressions automate motion; they don’t create texture. A wiggle()-heavy distortion rig still won’t look like real signal damage — for that, compositing pre-rendered footage wins. The free glitch overlays drop over any footage with a Screen blend mode and give you scan damage no expression can fake. And if you’re on a machine without After Effects at all, several of the free After Effects alternatives support similar scripting.

FAQ

How do I add an expression in After Effects?

Alt-click (Windows) or Option-click (Mac) the stopwatch icon next to any property. The property value turns red and an expression field opens in the timeline. Type or paste the code and press Enter on the numeric keypad to apply it.

Why does my expression show an error and a yellow warning banner?

The most common causes are a typo in a layer or effect name inside quotes (names must match exactly, including spaces), applying a 2D expression to a property with a different number of dimensions, or a missing bracket. After Effects disables the expression and shows the error; fix the code and re-enable it.

Do expressions slow down rendering?

Lightweight expressions like wiggle() or time * 100 are negligible. Expressions that reference other layers’ properties on every frame — like valueAtTime() chains across many layers — can add up in complex comps. If a finished comp is final, you can convert an expression to keyframes via Animation > Keyframe Assistant > Convert Expression to Keyframes.

What’s the difference between wiggle() and Math.sin()?

wiggle() is randomized — every frame deviates unpredictably within your amplitude, which reads as handheld or organic motion. Math.sin() is a perfectly regular wave — the same cycle repeats identically, which reads as mechanical or floating motion. Use wiggle for camera shake, sine for pendulums and hovering.

Enjoy this article?

Share it with your creative community and help others discover great content.