expressions worth keeping
how do i add an expression in after effects? alt-click (option-click on mac) the stopwatch next to the property, paste over the text that appears, and click anywhere outside it. the property's value turns red and follows the expression from then on.
the ones that end up in almost every project here. find what you want it to do, paste it on that property, and change the numbers at the top. the rest you can leave alone. each one has a small example, drawn in your browser with that expression's own math and numbers (wiggle's randomness won't match after effects exactly).
| what i want it to do | use | property |
|---|---|---|
| squash wide and short, then tall and skinny, after a keyframe | jello | scale |
| go past a keyframe and spring back | overshoot | anything |
| rock side to side after a keyframe | wobble | rotation |
| repeat my keyframes forever | loop | anything |
| shake randomly | wiggle | anything |
| spin forever | spin | rotation |
| grow and shrink forever | pulse | scale |
| follow another layer, a bit late | follow | position |
| type on letter by letter | typewriter | source text |
| count up a number | counter | source text |
| keep the anchor in the middle | center anchor | anchor point |
| flicker on and off | flicker | opacity |
keyframe bounces
keyframe the property like normal, then paste on that same property. the bounce kicks in right after every keyframe. change the top 3 lines, leave the rest alone.
jello
scaleafter each scale keyframe it squashes wide and short, then tall and skinny, back and forth until it settles.
amount = 15; // how much it squishes, in %
speed = 3; // squishes per second
settle = 5; // how fast it calms down (higher = shorter)
n = numKeys ? nearestKey(time).index : 0;
if (n > 0 && key(n).time > time) n--;
if (n == 0) {
value;
} else {
t = time - key(n).time;
w = amount * Math.sin(speed * t * 2 * Math.PI) * Math.exp(-settle * t);
value + [w, -w];
}
tall and skinny first: change the last line to value + [-w, w];. on a 3d layer, add a 0 inside the brackets on the last line: [w, -w] becomes [w, -w, 0].
overshoot
anythinggoes past the keyframe and springs back. the faster it was moving, the bigger the overshoot.
amount = 0.05; // how far past it goes (0.05 = a little, 0.2 = a lot)
speed = 4; // springs per second
settle = 6; // how fast it calms down (higher = shorter)
n = numKeys ? nearestKey(time).index : 0;
if (n > 0 && key(n).time > time) n--;
if (n == 0) {
value;
} else {
t = time - key(n).time;
v = velocityAtTime(key(n).time - 0.001);
value + v * amount * Math.sin(speed * t * 2 * Math.PI) * Math.exp(-settle * t);
}
wobble
rotationwobbles side to side after each rotation keyframe, then settles.
amount = 15; // how far it rocks, in degrees
speed = 3; // rocks per second
settle = 5; // how fast it calms down (higher = shorter)
n = numKeys ? nearestKey(time).index : 0;
if (n > 0 && key(n).time > time) n--;
if (n == 0) {
value;
} else {
t = time - key(n).time;
value + amount * Math.sin(speed * t * 2 * Math.PI) * Math.exp(-settle * t);
}
jello on a marker
scaleno keyframes needed. drop a layer marker wherever you want it to jiggle.
amount = 15; // how much it squishes, in %
speed = 3; // squishes per second
settle = 5; // how fast it calms down (higher = shorter)
n = marker.numKeys ? marker.nearestKey(time).index : 0;
if (n > 0 && marker.key(n).time > time) n--;
if (n == 0) {
value;
} else {
t = time - marker.key(n).time;
w = amount * Math.sin(speed * t * 2 * Math.PI) * Math.exp(-settle * t);
value + [w, -w];
}
on a 3d layer, add a 0 inside the brackets on the last line: [w, -w] becomes [w, -w, 0].
jello, different on every keyframe
scaleone row per keyframe, top row = keyframe 1: how much, how fast, how quick it settles. each hit keeps going when the next one lands, so nothing snaps.
// JELLO PER KEYFRAME (on Scale)
// One row per Scale keyframe. Top row = keyframe 1.
// amount = how much it squishes, in % (0 = none, minus = tall first)
// speed = squishes per second (your fps / frames between keys: 30 fps, 10 f apart = 3)
// settle = how fast it calms down (higher = shorter)
jello = [
// amount speed settle
[ 3, 3, 4 ],
[ 3, 3, 4 ],
[ 3, 3, 4 ],
[ 3, 3, 4 ],
[ 3, 3, 4 ]
];
// every keyframe's jello keeps going and they add up, each one eases in
s = 0;
for (i = 1; i <= numKeys && key(i).time <= time; i++) {
row = jello[i - 1];
if (!row || row[0] == 0) continue;
t = time - key(i).time;
s += row[0] * Math.sin(row[1] * t * 2 * Math.PI) * Math.exp(-row[2] * t) * (1 - Math.exp(-20 * t));
}
value + [s, -s];
if the motion is fighting, set speed to your frame rate divided by the frames between keys. 30 fps with keys 10 frames apart = 3. then each new key pushes with the squish instead of against it. on a 3d layer, add a 0 inside the brackets on the last line: [s, -s] becomes [s, -s, 0].
tilt paired with jello
rotationon rotation of the same layer. it rocks on the scale keyframes, one number per scale keyframe, in degrees.
// Tilt on every Scale keyframe. One number per Scale keyframe, in degrees.
// 0 = no tilt, minus = rocks the other way first.
tilts = [0, 5, 2, -1.5, 2];
speed = 2.5; // rocks per second (a bit slower than the jello)
settle = 4; // how fast it calms down
sc = transform.scale;
r = 0;
for (i = 1; i <= sc.numKeys && sc.key(i).time <= time; i++) {
a = tilts[i - 1] || 0;
t = time - sc.key(i).time;
r += a * Math.sin(speed * t * 2 * Math.PI) * Math.exp(-settle * t) * (1 - Math.exp(-20 * t));
}
value + r;
loops and wiggle
repeat what you keyed, or shake it.
loop
anything with keyframesrepeats your keyframes after the last one. swap the word in the quotes for the kind of loop.
loopOut("cycle");
"cycle"plays the keyframes over and over"pingpong"plays forward, then backward, forever"offset"keeps adding on each time, like a staircase"continue"keeps going at the last speed, no repeat
for a smooth cycle, make the last keyframe match the first.
wiggle
anythingthe first number is how often, the second is how far.
wiggle(2, 30);
w = wiggle(2, 30);
[w[0], value[1]];
posterizeTime(8);
wiggle(2, 30);
wiggle that loops
anythingends exactly where it started, so it loops clean. change the top 3 lines; loopTime is your loop length in seconds.
speed = 1; // wiggles per second
amount = 50; // how far
loopTime = 3; // loop length in seconds
// --- leave the rest ---
t = time % loopTime;
w1 = wiggle(speed, amount, 1, 0.5, t);
w2 = wiggle(speed, amount, 1, 0.5, t - loopTime);
linear(t, 0, loopTime, w1, w2);
motion
spin, pulse, follow and stagger, mostly with no keyframes at all.
spin
rotation90 = degrees per second. make it negative to spin the other way.
value + time * 90;
pulse
scalegrows and shrinks forever, on top of the size you set. change the top 2 lines.
amount = 5; // how much it grows, in %
speed = 1; // pulses per second
s = amount * Math.sin(time * speed * 2 * Math.PI);
value + [s, s];
on a 3d layer, add a 0 inside the brackets on the last line: [s, s] becomes [s, s, 0].
follow
positioncopies another layer's movement, 0.15 seconds late. change "Leader" to that layer's name.
thisComp.layer("Leader").transform.position.valueAtTime(time - 0.15);
thisComp.layer(index - 1).transform.position.valueAtTime(time - 0.08);
the second one follows whatever layer is right above this one. paste it on a stack of layers for a snake trail.
stagger
anything with keyframesanimate one layer, paste this, then duplicate it. each copy starts 0.05 seconds after the one above.
valueAtTime(time - (index - 1) * 0.05);
text
all of these go on source text. the first two need a slider control on the layer (effect → expression controls → slider control).
typewriter
source texttypes on letter by letter. keyframe the slider from 0 to the number of letters.
value.substr(0, Math.round(effect("Slider Control")("Slider")));
counter
source textcounts up a number. keyframe the slider from the start number to the end number.
Math.round(effect("Slider Control")("Slider"));
Math.round(effect("Slider Control")("Slider")).toLocaleString();
copy another layer's text
source textchange "Title" to the layer's name. edit that one and this updates.
thisComp.layer("Title").text.sourceText;
extras
small ones that save a lot of fiddling.
center anchor
anchor pointkeeps it in the middle, even when the text or shape changes size.
r = sourceRectAtTime(time, false);
[r.left + r.width / 2, r.top + r.height / 2];
flicker
opacityflickers on and off at random, up to 12 times a second.
posterizeTime(12); // how often it can flip, per second
random() > 0.3 ? 100 : 0; // 0.3 = off about 30% of the time
random per layer
anythingevery duplicate gets its own random value that doesn't change. here it's a rotation from 0 to 360.
seedRandom(index, true);
random(0, 360);
common questions
why doesn't my bounce do anything?
the keyframe bounces kick in right after a keyframe on the same property they're pasted on, so with no keyframes there, nothing happens. jello on a marker needs a layer marker instead, and the tilt reads the scale keyframes.
why does the typewriter or the counter show an error?
they read a slider called Slider Control on the same layer. add one with effect → expression controls → slider control, and keep its name.
how do i turn an expression off without deleting it?
click the = switch next to the property. click it again to turn it back on.
which expression engine are these for?
javascript, the default since after effects 16.0. the engine is under file → project settings → expressions.
how do i turn an expression into keyframes?
select the property and choose animation → keyframe assistant → convert expression to keyframes. it bakes one keyframe per frame and switches the expression off.
will a project with these open for someone else?
yes. they're plain after effects expressions, with nothing to install, so the project opens and renders the same on any machine.