Skip to main content

After Effects Expressions reference

Everyday Things

Elastic (‘Inertial Bounce’)

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){
v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
amp = .05;
freq = 4.0;
decay = 2.0;
value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
value;
}

Fade in/out without keyframes

fadeInTime = .5; // fade in time (seconds)
fadeOutTime = .5;

Math.min(linear(time,inPoint,inPoint + fadeInTime,0,100),linear(time,outPoint - fadeOutTime,outPoint,100,0))

Loop (AE 2019 + later)

loopOut()

Y-only Wiggle

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

Jumpy Wiggle

v=wiggle(5,50);
if(v < 50)v=0;
if(v > 50)v=100;

Low FPS Wiggle

posterizeTime(6); //ex. 6fps
wiggle(5,50); //freq,amplitude

LookAt:

delta = position – thisComp.layer(“Look-to-look-at”).transform.position;

radians_to_degrees(Math.atan2(delta[1],delta[0])) + 90

LookAt with a delay

delta = position – thisComp.layer(“Layer-to-look-at”).transform.position.valueAtTime(time-0.3);

radians_to_degrees(Math.atan2(delta[1],delta[0])) + 90

Fade In any property

fadeInTime = .5; // fade in time (seconds)
fadeOutTime = .5;

Math.min(linear(time,inPoint,inPoint + fadeInTime,0,100),linear(time,outPoint – fadeOutTime,outPoint,100,0))

Expression Controls

Clamp Slider values (example is position x+y)

theThing = -thisComp.layer("PQ Control").effect("lyft")("Slider");
[clamp(theThing, min=0, max=-theThing), clamp(theThing, min=0, max=-theThing)]

Checkbox control

if ( comp(“Comp 2”).layer(“Adjustment Layer 2”).effect(“Box”)(“Checkbox”) > 0 ) {100} else {0}

Round up expressions to integers/whole numbers: Math.floor

Math.floor (**your expressions here!**)

This will remove any decimals in the value and round to nearest whole number.

Text Layers

Center Anchor Point of text layer dynamically

boxTop = thisLayer.sourceRectAtTime(time).top;
boxHeight = thisLayer.sourceRectAtTime(time).height;

[value[0], boxTop + boxHeight/2 ];

Shape Layers

Shape Layer match Text layer above it

//layer's position property:
xpos = thisComp.layer(index-1).position[0];
ypos = thisComp.layer(index-1).position[1];
[xpos,ypos]

//Rectangle's size:
siz = thisComp.layer(index-1).sourceRectAtTime(10);
[siz.width,siz.height]

Sign up to this for fun stuff