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 them as FFX presets for AE CS3 here.
Are you looking to learn more about After Effects Expressions? Check out my complete training series on the topic in the graymachine store.
1. Intertial Bounce
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;
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);
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 techinically don’t need it in this case. Therefore, all you need to do is pickwhip your layer where the “layer =” variable is.
Pingback: Tweets that mention graymachine » Blog Archive » My 5 Favorite Expressions -- Topsy.com
Thanks Harry, these are very handy.
Thanks Harry, these are worth remembering.
Here’s some animation preset’s I made for inertial bounce (Beaver’s version of it):
http://www.stevekirby.co.uk/files/InertialBouncePresets.zip
There’s more information about them on the mograph post:
http://mograph.net/board/index.php?showtopic=13954&st=40
Hey steve. Thanks, I forgot to put that link to the original mograph post. I had asked Alan (Beaver) if he wanted credit for that expression, and he said “No way”. So, but it’s still good to reference the original. That’s the place I always used to go to grab that expression, and I finally got around to making a preset for it. It just always bugged me that the variables were in the middle of the expression.
Pingback: Harry’s Top Five Expressions | Motionworks
cool list!
I always stress ten cool basic things – I’m shocked how often advanced artists don’t use just a simple expression to help them do stuff.
1. Map to Time
2. Mute keyframes
3. Use Expression effects (sliders, knobs, etc)
4. Do Basic Math
5. Interpolate values using linear
6. Layer Space transformations
7. Wiggle
8. using index to get unique ids
9. using strings in the text source
10. sin waves
c
Pingback: uberVU - social comments
Thanks, man! I use the toComp expression in almost every project as well. Looking forward to looking at the others!
thanks a lot for this useful collection.
Thanks Harry this is a great resource – been using expressions for a while, learning bits here and there. The autofade one will save me hours!
I will explore this expression and see what they do. I’m not really familiar with them or how they work.
But will try them. THANKS!
Thanks ,dude
You forgot one of the most basic and probably the most useful of all expressions:
loopOut(“Cycle”,0)
This lets you loop out keyframes on your timeline – extremely useful for long animations or comps or when you need an action to continue throughout the piece. I love using it with particles, pre-existing footage that is time-remapped, position, opacity… You name it. You can change the expression from endless to looping however many times by changing the “0″ to whatever number of times you need the item to loop. It sure beats copying and pasting keys!
Thanks Suztv. Coincidentally, I am using this one a lot on the current project I am working on. It is definitely useful, and definitely would be in my next top 5.
You are very hot Harry, and handsome guy…;)
Thanks!!
I´m one of those guys that can´t get my head around expressions
I use wiggle and random a lot but that´s about it.
Any suggestions on how to understand the language of expressions?
//Klas
Check out :
http://www.graymachine.com/2009/04/after-effects-expressions/
You can watch Lesson 1 for free!
Pingback: 40 great AE tutorials | Detroit Digital Media
very handy Harry
thank you!!!
Pingback: 5 favorite expressions for After Effects, courtesy of graymachine | LXB | LESTERBANKS
thanks very much.
i especially appreciate the toComp script. very useful and fresh to me. BTW gorgeous site, cool clean and crisp.
Expressions sometimes do my head in. This might just help me out. The Inertial bounce is awesome!!
Thanks!
How work “inertial bounce”? I’ve instal preset but it’s nothing. What I must modify for see something?
Create two keyframes on position or scale.. if the motion is fast enough, the object will bounce. It’s really just that simple.
Hey Frank!
Very helpful expressions.
Is there any way to use the Intertial Bounce expression so that it will effects each letter of a word e.g. scaling up.
I applied it to scale and it works great with the whole word.
I also tried to apply it to the scale parameter of an animator but that doesn’t work for me.
Any ideas?
Thanks a lot!
Grischa
I added a wiggle to the animator that was doing 3D position. The mode was “Add” and I keyed Min 0 at start and finish and then keyed -15 in the middle and it gave and nice little one bounce effect.
Not Inertial but not bad!
Hi Harry, I have a simple problem that I can’t solve.
I can see that there is a presets download, but Im trying to make some presets for myself.
Well, is easy to select the property that already have an expression and save it as preset.
But in some cases (like in the inertial bounce) the kind of expression can be applied to many properties. So, how can I store only the expression?
I have a very bad english, so..
In example:
I set the inertial bounce expression to the position property;
Select Position and Save animation preset.
Then, if I want to apply that preset to another layer’s scale…
Is there a way to stores expressions that not be notepad?
Hey, I founded a very nice script called expression toolbox (in AEscripts). I think that solve my problem.
Thanks for all.
hi. nice work!! im new n AE. how is the basic to use fadeinfade out preset? there any tutorial with simple explain? or link to see how to use. thnaks!
Pingback: bounce & swing kinetic text expressions for after effects
Pingback: 5 Easy After Effects Expressions | Wizpress.com
Pingback: Latest Hot Collection of Resources for After Effects Expressions
Thanks a lot for sharing these great expressions. That first one is a killer!!
Bummer, loved finding this post and the downloadable resources, but the presets don’t work in AE CS5 it would appear. Those for CS3 have an extention on them of .ffx. I notice the files in my presets folder that do work don’t have that.
Does anyone know if there is a downloadable update for more recent versions of AE?
As for just running the scripts, I get errors, and I certainly need and have much to learn, doing as much as I can as quick as I can. I’m super excited for the Intertial Bounce. Sounds like just what I wish for.
Oops, sorry for that last post. I figured it out, looking at things wrong somehow. Must not be fully recovered from the flu this last weekend.
I appreciate the great site and resources.
Hey Harry,
Thanks for the expressions. I think I really could have used one in a quick video I made. I faked a sunset in a timelapse where each still lasted 5 frames. I had “the sun” drop and move to the left every five frames of course. I tried to cleverly think of an expression but came up empty, so I key framed the whole thing (with 20 minute pauses looking for an expression online and watching your toolfarm tutorial, I thought the dragon was my answer!) Do you know if I could have used an expression? Here is a link to the vid for reference.
http://youtu.be/xL2aV669hdE
Pingback: Espressione: decadimento – Luca Passoni
Fantastic Harry, thanks so much for sharing these
Referring to the Inertial Bounce script, how would on apply it to an object’s scale in order to make it appear to pop into existence, then gently settle into a final scale?
Nevermind! I figured it out. I set keyframes and applied the expression. Nice!
I couldn’t get Inertial Bounce to work on a nested comp, just a layer.
Thanks for these, really like that it reacts to the outpoint of a layer!
Very nice write-up. I absolutely appreciate this website.
Thanks!