I realize that expressions can be daunting, and some would rather copy and past useful code rather than learn the language. That’s cool with me. Therefore, I’d like to share with you my 5 favorite expressions. These are expressions I use in just about every project, and I consider them to be incredible workflow enhancements.

Download the AE Presets

1. Intertial Bounce v1.2

Essentially, Inertial Bounce creates a bouncing motion of any parameter from one keyframe to the next, based on its velocity. Being that true “velocity” includes the vector (or traveling direction in 3D space), the bounce happens in whatever direction the object is traveling. This also accounts for scalar or array values, so you’ll find that this expression works just as well on 2D rotation as it does on 3D position. It’s very cool! This expression is a bit of a community effort. The seeds were certainly planted by the great Dan Ebberts, and then a modified version was posted on mograph.net. Although I’ve made a slight modification to it to make it a little more user friendly, it’s nothing that I will lay claim to as my own code. Nonetheless, it’s a great helper and I use it all the time. Modify “amp” for the amplitude or how much bounce is present. The variable “freq” is the frequency, or how frequently the bounce occurs. The “decay” is like a friction or mass setting, a higher value means a shorter decay over time.

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

2. Autofade

This is nothing brilliant, but it is something I wrote and use all the time. You’ll also find something similar in the After Effects preset “Behaviors” called Fade In + Out, which uses the Solid Composite effect and a custom interface. But, I like a simpler version that I use on Opacity. This is a slightly enhanced version that I’d revamped since I posted it in the “Auto Slideshow” presets and added the option to use markers. If there are no markers, the transition variable is used (where is says “transition=20″, this is in frames.) If there are *2* markers, the first marker is used for end point of the fade in, and the second marker is used to define the start of the fade out.

//Autofade: Add to opacity
transition = 20;       // transition time in frames
if (marker.numKeys<2){
tSecs = transition / ( 1 / thisComp.frameDuration); // convert to seconds
linear(time, inPoint, inPoint + tSecs, 0, 100) - linear(time, outPoint - tSecs, outPoint, 0, 100)
}else{
linear(time, inPoint, marker.key(1).time, 0, 100) - linear(time, marker.key(2).time, outPoint, 0, 100)
}

3. Snap Zoom In/Out

This is a cool expression to use on text. It creates a “snap” zoom on the in and out of the layer by modifying scale.

//Snap zoom in and out: apply to scale
snapScale = 300; //percent of scale to zoom
trans = 4; //  transition time in frames
trans = trans * thisComp.frameDuration;
inTrans  = easeOut(time, inPoint, inPoint + trans, [snapScale,snapScale], [0,0]);
outTrans = easeIn(time, outPoint, outPoint - trans, [0,0], [snapScale, snapScale]);
value+ inTrans + outTrans

If you prefer to use Z space position instead of scale, try this one:

zoom = 5000; //distance to zoom
trans = 4; //  transition time in frames
trans = trans * thisComp.frameDuration;

inTrans  = easeIn(time, inPoint, inPoint + trans, [0,0,zoom], [0,0,0]);
outTrans = easeOut(time, outPoint, outPoint - trans*2, [0,0,0], [0,0,zoom]);
value+ inTrans - outTrans

4. Y Axis Jitter

This is from Lesson 5 of my expressions series. This creates a random jittery motion in the Y axis. You can modify probability to make or less jitter, and the pos variable to define how large the jitter is.

// Y Axis Jitter
probability = 8 ;  //higher is less likely
pos = 50;
val  = random(-probability-2, 1);
m = clamp(val, 0, 1);
y = wiggle(10, pos*m)-position;
value + [0, y[1]]

5 . toComp

This one you’ll have to watch a short tutorial for here, and you can read a lot more about it at motionscript.com. The idea is that you can apply the equivalent 3D location to any 2D location. This might not sound exciting. But, think of all the 2D parameters out there, like lens flare location, Shine source, beams, etc. It is probably my most commonly used expression. But, the basic idea is this:

layer = thisComp.layer("Null 1")
layer.toComp([0,0,0])

Note: I intentionally left off the semicolon, as you technically don’t need it in this case. Therefore, all you need to do is pickwhip your layer where the “layer =” variable is.