Download Started!

Your download has begun.

olafmotion
Back to blog

After effects expression examples

Illustration of animated layers with expressions in After Effects showing dynamic motion design

If you’re looking for After Effects expression examples, here’s the direct answer: expressions are small JavaScript-like snippets you paste onto properties (Position, Opacity, Scale, etc.) to automate animation, create procedural motion, and link layers together-often replacing piles of keyframes with a few lines of logic. Once you get comfortable with a handful of core patterns (wiggle, loops, time-based math, layer-space conversions, and controls like sliders/checkboxes), you can build animations that stay flexible, art-directable, and fast to iterate.

This article is a practical, deep library of expression ideas you can copy, adapt, and combine. I’ll show the “why” behind each example, not just the code-because the real superpower is understanding how to bend these patterns to your own comps. All examples assume modern After Effects expressions (JavaScript syntax) and are written to be readable, tweakable, and production-friendly as of 2026-05-20.

What are After Effects Expressions?

Expressions in After Effects are code-based relationships you attach to a property. Instead of telling a layer “be here at frame 12, then there at frame 48,” you can tell it “follow that layer,” “oscillate,” “loop,” or “react to speed.” Think of expressions as a tiny rules engine living inside your timeline.

They’re not plugins and they’re not scripts. Scripts run once and change your project; expressions evaluate continuously as the comp plays or renders. That continuous evaluation is why expressions are so good at building motion systems that stay alive when you change your mind (and you will).

What is the purpose of expressions in After Effects?

The purpose is simple: control and automation. Expressions let you define motion and behavior with logic rather than manual keyframes. That can mean anything from adding natural randomness (camera shake), to enforcing consistency (all lower-thirds share the same ease), to building rigs (a character’s head follows a controller null).

Another big purpose is relationship. Keyframes are isolated-each property is its own little island. Expressions build bridges: this layer’s opacity depends on distance to camera; this text’s tracking depends on a slider; these 20 dots offset themselves based on index. Once you start thinking in relationships, you stop animating “things” and start animating “systems.”

And yes, expressions are also a way to avoid repetitive work. Looping, staggering, bouncing, delaying, syncing-these are all chores that expressions turn into one-liners.

How do expressions enhance animation workflows?

Expressions enhance workflow by making animation non-destructive and iterable. If your client asks, “Can the shake be half as intense?” you don’t want to re-keyframe 40 layers. You want to drag a slider. Expressions make that kind of change cheap.

They also enhance workflow by encouraging modularity. You can create a “control” layer with sliders and checkboxes, then have multiple layers read those values. This is how you build motion templates, brand kits, and reusable setups without feeling like you’re building a fragile house of cards.

Finally, expressions reduce timeline clutter. A clean timeline is not just aesthetic-it’s cognitive load. When your keyframes are minimal and your behavior is centralized, you spend less time hunting and more time designing motion.

πŸ“Έ See it in action on Instagram

Basic After Effects Expression Examples

Let’s start with the classics-the expressions you’ll use so often they’ll become muscle memory. These are foundational because they teach you the main “verbs” of expression work: randomness, repetition, and time.

To add an expression to a property: Alt/Option-click the stopwatch, then paste the code. If you see errors, don’t panic-After Effects is picky about quotes, parentheses, and property names. We’ll troubleshoot later.

Wiggle expression to add random movement

The wiggle expression is the gateway drug of expressions-tiny, powerful, and immediately satisfying. As the context data puts it: “The wiggle expression is one of the most common After Effects expressions.” It creates random motion that feels organic: handheld drift, nervous UI jitter, floating particles, subtle text shimmer.

Syntax: the wiggle function takes two arguments: frequency and amount. You’ll often see it written exactly like this:

wiggle(2,30)

That means “wiggle 2 times per second up to 30 units.” On Position, those units are pixels; on Rotation, degrees; on Opacity, percentage points. As the provided note explains: “So, using wiggle(2,30) will make the layer wiggle 2 times per second up to 30 pixels in any direction.”

Try these practical variations:

  • Subtle handheld drift (Position): wiggle(0.6, 12)
  • UI micro-jitter (Position): wiggle(10, 3)
  • Flickering neon (Opacity): wiggle(8, 25)
  • Wobbly rotation (Rotation): wiggle(2, 8)

Tip: Wiggle is random, but not chaotic. It produces smooth noise, not frame-by-frame jitter. If you want choppier motion, you can posterize time (advanced trick), but start here-it’s usually what you actually want.

Common pitfall: wiggle on Position affects both X and Y. If you want only X or only Y, you can isolate components:

freq = 2; amp = 30;
w = wiggle(freq, amp);
[w[0], value[1]]

This keeps Y locked while X wiggles.

Watch a battery loading animation breakdown

Looping animation with loopOut and loopIn

Looping is where expressions stop being “cute” and start being “production.” If you’ve ever keyframed a spin and then duplicated keyframes for 20 seconds… you deserve better.

loopOut() repeats keyframes beyond the last keyframe; loopIn() repeats before the first keyframe. The context data highlights the typical use: “Expressions can be used to loop and extend animation without adding additional keyframes…”

Apply this to any property that already has keyframes:

loopOut()

By default it cycles. But you can specify a mode. As noted in the context: the first argument can be "cycle", "continue", "offset", or "pingpong" (often written as "ping-pong" in tutorials, but AE’s actual string is typically "pingpong"). A canonical example from the data:

// loopOut set to cycle all keyframes
loopOut("cycle", 0);

Here are the modes you’ll actually use:

  • Cycle: repeats the same motion. Great for spinning, blinking, bouncing.
  • Pingpong: plays forward then backward. Great for yoyo motion, breathing scale.
  • Continue: extrapolates velocity. Great for motion that should keep going at the same speed.
  • Offset: repeats but adds the difference between first and last keyframe each cycle. Great for “keep climbing stairs” style motion.

Example: infinite yoyo scale (keyframe Scale from 100 to 110 over 10 frames):

loopOut("pingpong")

Example: keep rotating at the same speed (keyframe Rotation from 0 to 360 over 2 seconds):

loopOut("continue")

And don’t forget loopIn() when you need pre-roll. For instance, if you want a looping background animation already in motion when the comp starts, animate it in the middle and use loopIn/Out to extend both directions.

Animating rotation based on time

Time-based expressions are the cleanest form of procedural animation: no keyframes, just math. The simplest rotation-over-time is:

time * 90

That rotates 90 degrees per second. Want one full rotation every 2 seconds? That’s 180 degrees per second:

time * 180

But time-based animation gets more interesting when you use sine/cosine to create circular motion. The context data includes a classic “revolve in a circle” pattern:

var centerOfComp = [(thisComp.width/2),(thisComp.height/2)];
var circleOverTime = [Math.sin(time)*50, -Math.cos(time)*50];
centerOfComp + circleOverTime;

That expression goes on Position. It places the layer at the comp center and offsets it in a circle with a radius of 50 pixels. The negative cosine simply aligns the circle so it starts at the top rather than the right-an aesthetic choice, not a law of physics.

Make it art-directable by exposing radius and speed:

radius = 120;
speed = 1.2; // radians per second-ish
c = [thisComp.width/2, thisComp.height/2];
o = [Math.sin(time*speed)*radius, -Math.cos(time*speed)*radius];
c + o

Pro move: If you want a “clock hands” relationship (minute hand drives hour hand, etc.), you can link rotations between layers using pick whip or expressions. The context hints at this clock metaphor: different layers rotate at different speeds, staying logically tied together. In practice, you’d do something like: hour hand rotation equals minute hand rotation divided by 12, and so on.

Controlling Animations with Slider and Checkbox Controls

Expressions become genuinely usable in real projects when you stop hardcoding numbers and start driving them with controls. The idea is simple: put a Slider Control or Checkbox Control effect on a layer (often a Null named “CTRL”), then read that value in expressions.

The context data says it plainly: “Expressions can be keyframed by replacing values with links to expression controls, like a Slider Control.” This is how you hand off a project to another animator (or to Future You) without leaving a trail of mystery numbers.

How to control wiggle intensity with Slider control

Let’s take wiggle and make it adjustable. The context provides a very practical recipe: “Add a Slider Control effect to any Layer and name it Wiggle Amount.” Then reference it in the expression.

Step-by-step:

  1. Create a Null layer named CTRL.
  2. Add Effect > Expression Controls > Slider Control.
  3. Rename the slider to Wiggle Amount.
  4. On the animated layer’s Position, add this expression.

Using the context’s example (kept intentionally close to the original):

var wiggleAmount = effect("Wiggle Amount")("Slider");
// Wiggles 4 times per second by the amount set by the Slider
wiggle(4, wiggleAmount);

In a real rig, you’ll likely read the slider from the CTRL layer rather than the same layer. That looks like this:

ctrl = thisComp.layer("CTRL");
amp = ctrl.effect("Wiggle Amount")("Slider");
freq = 4;
wiggle(freq, amp)

Now you can animate the slider itself. That’s the underrated trick: the wiggle can “wake up,” “calm down,” or “spike” without changing the expression. You’re keyframing control, not motion.

Optional upgrade: add a second slider for frequency:

ctrl = thisComp.layer("CTRL");
freq = ctrl.effect("Wiggle Frequency")("Slider");
amp = ctrl.effect("Wiggle Amount")("Slider");
wiggle(freq, amp)

This is how you build a reusable “shake rig” that can drive multiple layers consistently.

Using Checkbox controls to start or stop effects

Checkboxes are your on/off switches. They’re perfect for toggling a wiggle, enabling a flicker, switching between two behaviors, or creating “safe mode” versions of an animation for client review.

Set up:

  1. On your CTRL layer, add Checkbox Control.
  2. Name it Enable Wiggle.

Then on Position:

ctrl = thisComp.layer("CTRL");
on = ctrl.effect("Enable Wiggle")("Checkbox");
amp = ctrl.effect("Wiggle Amount")("Slider");
freq = 4;
if (on == 1){
wiggle(freq, amp);
}else{
value;
}

This pattern-if enabled, do the fancy thing; else, return value-is the backbone of controllable rigs. It also makes troubleshooting easier: if something looks wrong, turn features off one by one until the culprit confesses.

Variation: Use the checkbox to freeze the animation at a specific time (like a paused noise texture). That’s a deeper trick involving posterizeTime() or sampling at a fixed time; but the same checkbox logic applies.

Advanced Expression Examples for Layer Interaction

This is where expressions start feeling like puppeteering. Instead of animating a layer in isolation, you make it respond to other layers, to markers, to parenting, or to its own index. These are the setups that turn “I can animate” into “I can build tools.”

Important concept: After Effects has multiple coordinate spaces-layer space, comp space, world space. When you start mixing parenting and 3D, you’ll often need conversion methods like toComp(), fromComp(), toWorld(), and vector versions like toCompVec(). They sound abstract until you use them once-then they feel like glasses you didn’t know you needed.

Position one layer between two others

Say you have two layers-A and B-and you want a third layer (C) to always sit halfway between them. This is great for placing a label between two points, positioning a “midpoint” null for a bend, or keeping a graphic centered between moving elements.

On layer C’s Position (2D example):

a = thisComp.layer("A").transform.position;
b = thisComp.layer("B").transform.position;
(a + b) / 2

That’s the midpoint. Now let’s make it art-directable: add a slider called “Bias” (0 to 100) on CTRL, where 0 means stick to A, 100 means stick to B.

ctrl = thisComp.layer("CTRL");
bias = ctrl.effect("Bias")("Slider")/100; // 0..1

a = thisComp.layer("A").transform.position;
b = thisComp.layer("B").transform.position;
a + (b - a) * bias

Now you’ve got a layer that can slide along the line between two moving targets without any keyframes. This is also the core math behind “follow path between points” rigs.

3D note: If A and B are 3D layers, use their world positions (via toWorld(anchorPoint)) and then convert back if needed. For many cases, simply sampling their Position works if they share the same space, but world-space is safer in complex 3D setups.

Creating a delay effect on layer position from its parent

Delayed follow is the secret sauce of lively motion: the child follows the parent, but with a little lag, like it has weight. You can do this with keyframes and easing, but expressions make it scalable-especially when you have many layers.

The context data includes a parent-delay pattern using frames-to-time and coordinate conversions:

// Sets a delay amount in frames
var delay = 5;
// Offsets the layer's Position in time based on delay
parent.fromComp(toComp(anchorPoint, time - framesToTime(delay)));

Let’s unpack it. The idea is: sample where the layer would be at an earlier time, then use that as the current value. The coordinate conversion helps keep the result correct under parenting.

Here’s a slightly more controllable version using a slider for delay frames:

ctrl = thisComp.layer("CTRL");
delay = ctrl.effect("Delay (frames)")("Slider");

t = time - framesToTime(delay);
parent.fromComp( toComp(anchorPoint, t) )

If you want a cascading delay across multiple layers (like a snake), incorporate index:

ctrl = thisComp.layer("CTRL");
delayPerLayer = ctrl.effect("Delay Per Layer (frames)")("Slider");

t = time - framesToTime(delayPerLayer * (index-1));
parent.fromComp( toComp(anchorPoint, t) )

Now layer 1 leads, layer 2 follows a bit later, layer 3 later still. It’s a one-expression “stagger” that stays intact even if you change the parent’s animation.

See a real UI animation example built in After Effects

Animating scale at each layer marker

Markers are like little narrative beats on your timeline: “hit here,” “pulse here,” “emphasize this word.” Expressions can read marker times and trigger animation bursts without keyframing every burst.

The context data provides a robust example that finds the nearest marker and applies a wobble with sine and exponential decay. Here’s that pattern (again kept close to the provided snippet):

var n = 0;
var t = 0;
if (marker.numKeys > 0){
n = marker.nearestKey(time).index;
if (marker.key(n).time > time) n--;
}
if (n > 0) t = time - marker.key(n).time;
var amp = 15;
var freq = 5;
var decay = 3.0;
var angle = freq * 2 * Math.PI * t;
var scaleFact = (100 + amp * Math.sin(angle) / Math.exp(decay * t)) / 100;
[value[0] * scaleFact, value[1] / scaleFact];

What this does: every time you pass a marker, the layer “pops” and settles. Notice the clever touch: X scales up while Y scales down (or vice versa), creating a squishy, cartoony feel rather than a uniform zoom.

Make it more usable by linking amp, freq, and decay to sliders. Then you can decide whether the pop is a subtle UI emphasis or a full-on jelly wobble.

Workflow idea: For kinetic typography, place markers on the word layer at syllable hits, then let this expression do the rhythmic pulsing. You’re essentially turning markers into a performance track.

3D Layer Expression Examples

3D expressions feel like wizardry because they connect motion graphics to spatial logic: distance, facing direction, camera vectors. The key is understanding that a 3D layer has an orientation in space, and the camera defines what “toward” and “away” mean.

Two functions show up a lot here: toWorld() (convert a point to world coordinates) and toCompVec() (convert a direction vector into comp space). The context data specifically calls out using toCompVec() to determine facing direction and to hide or flip layers accordingly.

Fade opacity based on distance from camera

This is a classic depth cue: objects fade as they get farther from camera. It’s useful for particle fields, UI in 3D space, atmospheric perspective, or keeping distant clutter from shouting over your focal subject.

On a 3D layer’s Opacity:

cam = thisComp.activeCamera;
// world positions
p = toWorld(anchorPoint);
c = cam.toWorld([0,0,0]);

d = length(p, c);

near = 500; // fully visible closer than this
far = 2000; // fully invisible beyond this

linear(d, near, far, 100, 0)

Notes:

  • length(a,b) returns distance between two points.
  • linear() maps one range to another. Swap 100 and 0 if you want the opposite behavior.
  • Clamp if needed: clamp(linear(...), 0, 100) to avoid negative opacity.

If you use a custom camera (recommended), reference it by name: thisComp.layer("Camera 1"). Using activeCamera is convenient but can be ambiguous in some workflows.

Make 3D layer invisible if facing away from camera

Sometimes you want a layer to behave like a one-sided card: visible from the front, gone from the back. This is especially useful for 3D billboards, faux-3D UI panels, or scenes where you don’t want to see “the back of the sticker.”

The context provides a clean conditional example using toCompVec():

if (toCompVec([0,0,1])[2] > 0){
value;
}else{
0;
}

Put that on Opacity. It checks whether the layer’s local Z-axis (the direction it’s facing) points toward the camera in comp space. If it’s facing the camera, keep the current opacity (value); otherwise, set opacity to 0.

Practical tweak: If you want a soft fade near the edge rather than a hard cut, you can use the Z component as a driver and map it with linear(). That’s more advanced, but the same facing test is the foundation.

Flip layer horizontally based on orientation

Instead of hiding the back face, you might want the layer to “turn around” so it’s always readable. This can be handy for labels in 3D space or signage that should never appear mirrored.

The context data includes a scale-negation approach:

if (toCompVec([0, 0, 1])[2] > 0){
value;
}else{
[-value[0], value[1], value[2]];
}

Put that on Scale of a 3D layer. When the layer faces away, it flips X scale to negative, mirroring the layer horizontally.

Two cautions:

  • Negative scale can invert winding order and sometimes affects effects/shadows in unexpected ways. Test in your pipeline.
  • If the layer also has parenting, negative scale can create surprising results. In those cases, consider flipping via Rotation Y instead, or apply the flip on a precomp.

Creating Complex Effects with Expressions

This section is about building “effects” that feel like plugins, but are really just clever relationships. These are the kinds of setups that make expressions feel less like code and more like choreography: trails, bulges, camera focus rigs.

Complex doesn’t mean long. Often it just means you’re combining a few concepts: sampling time, measuring distance, converting spaces, and exposing controls.

Create a trail of images using expressions

A trail is basically “the past, drawn behind the present.” There are multiple ways to do this in After Effects (Echo effect, time displacement, duplicating layers), but expressions can create a controllable, lightweight trail system-especially when you want each clone to lag by a fixed amount.

Approach A: index-based time offset (best for many duplicates)

Duplicate your layer several times (or use a shape repeater / text animator depending on your setup). Then, on each duplicate’s Position, sample the leader’s position at an earlier time based on index:

leader = thisComp.layer("Leader");
framesDelay = 2; // each copy lags by 2 frames

t = time - framesToTime(framesDelay * (index-1));
leader.transform.position.valueAtTime(t)

Now each layer becomes a “ghost” of the leader at a slightly earlier time. Pair it with an opacity falloff so the trail fades:

copies = 12;
maxFade = 80; // how transparent the last one is

i = index-1;
linear(i, 0, copies-1, 100, 100-maxFade)

You’d set copies to match the number of duplicates you made. If you want it to auto-detect, you can use thisComp.numLayers with some naming conventions, but that’s beyond the clean-copy scope here.

Approach B: trail with “delay from parent” logic

If your trail layers are parented, you can adapt the delay expression pattern from earlier (sampling time - framesToTime()) to keep the trail consistent even under parenting and transformations.

Finishing touch: Add blur increasing with index, or tint shifting over time. Trails are as much about texture as they are about motion.

Create a bulge effect between two layers

Imagine two layers define endpoints-like two pins holding a rubber band. You want a third layer (or a set of points) to bulge outward between them, creating an arc. This can fake a bend, a bridge, a smile curve, or a stretchy connector.

There are many ways to do this depending on whether you’re driving a path, a shape, or a null. Here’s a practical “bulge a midpoint controller” setup: you place a layer at the midpoint between A and B, then offset it perpendicular to the line by a bulge amount.

On a null called “MidBulge” Position:

a = thisComp.layer("A").transform.position;
b = thisComp.layer("B").transform.position;

mid = (a + b) / 2

// direction from A to B
v = b - a;

// perpendicular vector (2D): [ -y, x ]
perp = [-v[1], v[0]];

// normalize
perpN = perp / length(perp);

bulge = thisComp.layer("CTRL").effect("Bulge")("Slider");

mid + perpN * bulge

Now you have a bulging midpoint that always stays “between” the two layers, but can be pushed out with a slider. If you’re animating a curved connector, you can use this null as a Bezier handle or as a control point for a shape path (via Create Nulls From Paths / expressions on path points).

Extra control: Add a checkbox “Flip Bulge” to invert direction, or multiply bulge by Math.sign() logic. Or make bulge depend on distance between A and B so the curve gets stronger as the endpoints separate.

Why this works: It’s the same midpoint math from earlier, plus a perpendicular offset. You’re building geometry with vectors-quietly, politely, inside After Effects.

Match camera focal plane to another layer

This is one of the most cinematic expression tricks: lock a camera’s focus distance to a target layer so depth of field stays perfectly synced. Rack focus becomes as easy as animating the target layer (or swapping the target).

The context data provides a solid focus-distance expression using world vectors and a dot product:

var target = thisComp.layer("target");
var V1 = target.toWorld(target.anchorPoint) - toWorld([0,0,0]);
var V2 = toWorldVec([0,0,1]);
dot(V1, V2);

Put that on the camera’s Focus Distance. Conceptually, it projects the vector from camera to target onto the camera’s forward axis, giving you the distance along the view direction.

Practical setup tips:

  • Name your focus target layer something obvious like FOCUS_TARGET.
  • Use a Null as the target so you can animate it independently of visible elements.
  • If your focus feels “off,” confirm your camera is the layer receiving the expression (not a different camera) and that depth of field is enabled.

Creative extension: Drive aperture with another slider so you can animate how “dreamy” the shot is without breaking focus. Or switch targets using a dropdown menu (Expression Control) for multi-character scenes.

How to Use Expressions Efficiently in Your Projects

Expressions are powerful, but they’re also easy to turn into a messy bowl of spaghetti if you treat them like magic spells you copy from the internet and never read again. Efficiency is about maintainability: clear naming, centralized controls, and predictable behavior.

This section is less about flashy code and more about building habits that keep your comps fast, flexible, and friendly to collaborators.

Organizing and managing expressions

Use a dedicated control layer. A single Null named something like CTRL or MASTER CONTROLS can hold sliders, checkboxes, angle controls, and color controls. Your expressions then reference one place, not a scavenger hunt across the timeline.

Group controls with naming conventions. Prefix controls with categories:

  • Shake – Amount, Shake – Frequency
  • Trail – Delay, Trail – Fade
  • Focus – Target (if using menus)

This makes the Effect Controls panel read like a UI rather than a junk drawer.

Comment your expressions. After Effects supports // single-line comments. A one-line explanation (“// sample leader position with per-layer frame delay”) saves time later. The context examples already model this style, and it’s worth copying as a habit.

Keep expressions local where appropriate. Not everything needs a global rig. If an expression is only used once and is self-explanatory, it can live directly on the property without a huge control system.

Be mindful of performance. Expressions evaluate often. Expensive calls inside many layers (like repeatedly searching for layers by name in every frame) can slow previews. Cache references inside the expression when possible (store layer references in variables), and avoid unnecessary loops.

Best practices for writing clean expressions

Start with readable variables. Compare:

wiggle(4, effect("Slider Control")("Slider"))

vs.

amp = effect("Wiggle Amount")("Slider");
freq = 4;
wiggle(freq, amp)

The second version is easier to debug and easier to hand to someone else.

Return the right type. Position expects an array like [x,y] (or [x,y,z] in 3D). Rotation expects a number. Scale expects an array. A common beginner error is returning a number to a property that expects an array, which triggers errors like “couldn’t turn result into numeric array.”

Use value as your default. If your expression is an add-on (shake, offset, bounce), build on top of value rather than replacing it completely. This preserves keyframes and makes mixing techniques easier.

Clamp when mapping ranges. When using linear() or ease(), values can overshoot. If a property has hard limits (Opacity 0-100), use clamp() to keep things sane.

Prefer framesToTime for frame-based offsets. If you think in frames (many motion designers do), write delays in frames and convert them. It keeps timing consistent even if you change comp frame rate.

Know when to stop. Expressions are not a replacement for taste. If you’re writing 80 lines to avoid setting 3 keyframes, you may be optimizing the wrong thing. Use expressions to remove repetition and create controllable behavior-not to prove you can code.

Troubleshooting common expression errors

Expression errors feel dramatic because they show up as angry yellow warnings and frozen properties. Most of them boil down to a few recurring issues.

1) Layer/effect/property name mismatch

If you reference thisComp.layer("CTRL") but your layer is named “Ctrl” or “CONTROL,” After Effects won’t guess. Same for effect names: if your slider is called “Wiggle Amount” but you reference “WiggleAmount,” it breaks. Solution: copy/paste names, or use the pick whip to generate references.

2) Wrong quotes or missing parentheses

AE expressions are sensitive to syntax. Straight quotes " " are required-curly quotes from rich text editors will fail. Parentheses must match. When in doubt, simplify: remove lines until it works, then rebuild.

3) Returning the wrong data type

As mentioned: arrays vs numbers. If you modify Position and accidentally return a single number, you’ll get an error. Fix by returning [x,y] or using value and altering one component.

4) 3D/2D confusion

A 3D layer’s Position is [x,y,z]. If you paste a 2D position expression returning [x,y], it may error or behave oddly. Solution: return three values, often [x,y,value[2]] if you want to preserve Z.

5) Parenting space issues

If something “drifts” unexpectedly under parenting, you may be mixing comp space and layer space. This is where conversion functions matter. The context data includes a useful reminder: to find the true position of a parented layer, convert coordinates with toComp():

var targetLayer = thisComp.layer("Parented Layer");
targetLayer.toComp(targetLayer.anchorPoint);

If your rig breaks when you parent something, it’s often not “wrong,” it’s just in the wrong space.

6) Nearest key/marker edge cases

Expressions that use nearestKey() or marker logic can fail when there are no keys/markers, or when time is before the first marker. Always guard with checks like if (marker.numKeys > 0) (as in the provided marker example). Defensive code is boring, and boring is stable.

Conclusion

Once you’ve got a small toolkit of expression patterns, the fun part is mixing them like ingredients. A wiggle becomes more useful when it’s gated by a checkbox and scaled by a slider. A loop becomes more elegant when it’s paired with a time offset so layers cascade. A camera focus rig becomes a storytelling tool when you animate the target’s movement rather than the camera’s settings.

If you want a practical next step, build yourself a tiny “expression playground” project: one comp with a CTRL null, a few shape layers, a 3D camera, and some markers. Treat it like a sketchbook. Try swapping linear() for ease(). Try driving bulge amount with distance. Try using the marker-pop scale on text, then on a logo, then on a 3D card. The goal isn’t to memorize code-it’s to develop intuition for how motion behaves when it’s described as a relationship instead of a timeline chore.

And if you ever get stuck, remember the most reliable debugging trick in After Effects expressions: return value, then add complexity one line at a time. Expressions reward patience-and they repay it with animations that stay flexible long after the first client change request arrives.

Browse more After Effects animation examples

Bartek

Motion Designer & Creative Director

Passionate motion designer specializing in creating stunning animations and visual effects for brands worldwide. With over 10 years of experience in After Effects, I craft eye-catching motion graphics that bring stories to life.

🎁

Free AE Template

Register now & get the Duolingo Widget template free + 20% off your first subscription!

Create Free Account β†’ No credit card required