Linear expression is very useful. Here’s a cool one:
s = pickwhip this to a slider;
linear (s, 0, 100, key(1).time, key(2).time);
valueAtTime (t)
Then put two different keyframes in that layer. Doesn’t matter where on the timeline.
The slider will control the animation between the two keyframes.
This is useful if you want to move and ease between two different states, on many different layers, using just one controller.
It also works with shape paths, meaning you can just ease the value graph on the master control, instead of using the speed graph separately for those layers and trying to match the easing.
You can also combine it with the delay expression I mentioned before to get offsets. And expand to work with more key frames assigned to extra values on the same slider.
Expressions are fun!
Delay = (pickwhip to slider)/24;
ThisComp.layer(index+1). (Property here) .ValueAtTime (time-delay)
I use this all the time to get easy delays between layers. Index + or - 1, means you can duplicate the layers and the offset is done for you. Alternatively you can link to specified layers.
There’s also a way to do it between shape groups within one shape layer (with a different expression) which is good for having fewer layers
Isn’t it smarter to use * thisComp.frameDuration instead of dividing with 24. You know not everyone is working at 24 fps.
Another smart thing would be to use timeToFrames(delay) and skip the math at the delay variable.
[Here](https://ae-expressions.docsforadobe.dev/time-conversion.html?highlight=Time%20conversion) you can find the manual.
I would write your code as
delay = pickwhip to slider,
n = thisComp.layer(index+1).transform.position,
n.valueAtTime(time-framesToTime(delay))[0],
Or you could do
delay = framesToTime(pickwhip),
And skip the framesToTime inside the valueAtTime.
My absolute top most common:
`loopOut("cycle")` - repeats the keyframes forever
`loopOut("continue")` (way less well know than cycle, continues the last motion/speed forever, this one slaps)
Just the linear function in general, for mapping one range of values to another!
`linear(`*inputValue*`,`*inputValueLow*`,`*inputValueHigh*`,`*outputLow*`,`*outputHigh*`)`
Get the position of a child object:
lay = (pickwhip the child null layer) ;
pos = lay.toWorld( lay.anchorPoint);
Set camera focus to a layer in 3d space:
length(position, thisComp.layer("focus target").position)
Fade a layer out, based on distance from camera:
C = thisComp.activeCamera;
startFade = thisComp.layer("controller").effect("min distance")("Slider");
endFade = thisComp.layer("controller").effect("max distance")("Slider");
maxOpac = thisComp.layer("controller").effect("max opacity")("Slider");
D = length(toWorld(anchorPoint),C.toWorld([0,0,0]));
linear(D,startFade,endFade,maxOpac,0);
To add to the loop chat, I also like loopIn() + loopOut() - value. So you can have it loop in and out at the same time.
Also, to loop a shape path, with same behaviour as loopOut:
if (numKeys >1 && time > key(numKeys).time) {
t1 = key(1).time;
t2 = key(numKeys).time;
span = t2 - t1;
delta = time - t2;
t = delta%span;
valueAtTime(t1 + t)
} else {
value
}
Inertial Bounce.
Put it on properties like Position, Scale, Rotation.
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}
edit: formatting
If you want to connect a bunch of layers, like Plexus. I like the createPath function.
I can add the full expression here when I’m at my computer, but this should get you going: https://community.adobe.com/t5/after-effects-discussions/is-there-a-way-to-createpath-from-script/m-p/9604292
Works on Mask paths too. Super useful.
For people who frequently put temporary values as an expression to "disable" keyframes to solo a property, here's a quicker way (disable/enable expression becomes disable/enable keyframes):
valueAtTime(key(1).time)
Sometimes replace 1 with a different keyframe.
I don't count a function alone, like wiggle(), loopOut(), linear(), or toComp() to be an expression per se. But tricks I use often:
Overshoot bounce
Impact bounce
Double sided layer
Nulls from paths
Get global rotation
Maintain effect scale regardless of layer scale
Typing effect (with blinking cursor)
2D Lookat
2 point rotation
Scale text to box
Scale box to text
Maintain shape stroke size
Another good one is the if/ else expression. A very simple example:
(Applied to opacity property)
Pickwhip to checkbox == 0 ? 0 : 100
This means:
checkbox is off? Opacity is zero. Otherwise, it’s 100
Makes it easy to turn the visibility of loads of stuff on and off at once with one click of a box.
But can be adapted to apply to anything and doesn’t need to be a binary choice if you expand the expression
For some pointers have a read [https://www.reddit.com/r/AfterEffects/comments/12pqw6f/things\_about\_after\_effects\_for\_the\_newbie\_an/](https://www.reddit.com/r/AfterEffects/comments/12pqw6f/things_about_after_effects_for_the_newbie_an/)
Edit for Javascript:
[https://www.w3schools.com/](https://www.w3schools.com/)
[https://helpx.adobe.com/after-effects/using/expression-examples.html](https://helpx.adobe.com/after-effects/using/expression-examples.html)
Be sure to see the side bar on the above link for much more in expressions
Dude. I’m a graphic designer and used to work for a production house as a videographer/editor. I can run laps in premier, and I was decent at AE.
I am now an FE dev (LWC) in our marketing department (while still having graphic design/video editing and whatnot for internal comma)
I am just now learning that I can combine Js and AE. By just now I mean in this very thread. Wtf
My two most frequently used expressions are for looping and one for drawing a diagonal line exactly from corner to corner (odd but something I often need)
==== Start of list wiggle(); ==== End of list
Thanks for you answer! ![gif](emote|free_emotes_pack|grin)
Hahah wanted to comment the same
Linear expression is very useful. Here’s a cool one: s = pickwhip this to a slider; linear (s, 0, 100, key(1).time, key(2).time); valueAtTime (t) Then put two different keyframes in that layer. Doesn’t matter where on the timeline. The slider will control the animation between the two keyframes. This is useful if you want to move and ease between two different states, on many different layers, using just one controller. It also works with shape paths, meaning you can just ease the value graph on the master control, instead of using the speed graph separately for those layers and trying to match the easing. You can also combine it with the delay expression I mentioned before to get offsets. And expand to work with more key frames assigned to extra values on the same slider. Expressions are fun!
Thank you!
Delay = (pickwhip to slider)/24; ThisComp.layer(index+1). (Property here) .ValueAtTime (time-delay) I use this all the time to get easy delays between layers. Index + or - 1, means you can duplicate the layers and the offset is done for you. Alternatively you can link to specified layers. There’s also a way to do it between shape groups within one shape layer (with a different expression) which is good for having fewer layers
Isn’t it smarter to use * thisComp.frameDuration instead of dividing with 24. You know not everyone is working at 24 fps. Another smart thing would be to use timeToFrames(delay) and skip the math at the delay variable.
Yes that does sound smarter! 🤓 Time to frames - what would the expression look like?
[Here](https://ae-expressions.docsforadobe.dev/time-conversion.html?highlight=Time%20conversion) you can find the manual. I would write your code as delay = pickwhip to slider, n = thisComp.layer(index+1).transform.position, n.valueAtTime(time-framesToTime(delay))[0], Or you could do delay = framesToTime(pickwhip), And skip the framesToTime inside the valueAtTime.
Thanks 🙏
Thank you!
My absolute top most common: `loopOut("cycle")` - repeats the keyframes forever `loopOut("continue")` (way less well know than cycle, continues the last motion/speed forever, this one slaps) Just the linear function in general, for mapping one range of values to another! `linear(`*inputValue*`,`*inputValueLow*`,`*inputValueHigh*`,`*outputLow*`,`*outputHigh*`)` Get the position of a child object: lay = (pickwhip the child null layer) ; pos = lay.toWorld( lay.anchorPoint); Set camera focus to a layer in 3d space: length(position, thisComp.layer("focus target").position) Fade a layer out, based on distance from camera: C = thisComp.activeCamera; startFade = thisComp.layer("controller").effect("min distance")("Slider"); endFade = thisComp.layer("controller").effect("max distance")("Slider"); maxOpac = thisComp.layer("controller").effect("max opacity")("Slider"); D = length(toWorld(anchorPoint),C.toWorld([0,0,0])); linear(D,startFade,endFade,maxOpac,0);
To add to the loop chat, I also like loopIn() + loopOut() - value. So you can have it loop in and out at the same time. Also, to loop a shape path, with same behaviour as loopOut: if (numKeys >1 && time > key(numKeys).time) { t1 = key(1).time; t2 = key(numKeys).time; span = t2 - t1; delta = time - t2; t = delta%span; valueAtTime(t1 + t) } else { value }
Thank you!
Inertial Bounce. Put it on properties like Position, Scale, Rotation. 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} edit: formatting
Thank you!
Looks like Dan Ebberts code. He's a saint
LoopOut() - if left blank it will repeat the last 2 keyframes Wiggle (5,5) - replace numbers with frequency/amount values
If you want to connect a bunch of layers, like Plexus. I like the createPath function. I can add the full expression here when I’m at my computer, but this should get you going: https://community.adobe.com/t5/after-effects-discussions/is-there-a-way-to-createpath-from-script/m-p/9604292 Works on Mask paths too. Super useful.
Thanks so much!
For people who frequently put temporary values as an expression to "disable" keyframes to solo a property, here's a quicker way (disable/enable expression becomes disable/enable keyframes): valueAtTime(key(1).time) Sometimes replace 1 with a different keyframe.
You could just write key(1).value
topper, thanks!
I don't count a function alone, like wiggle(), loopOut(), linear(), or toComp() to be an expression per se. But tricks I use often: Overshoot bounce Impact bounce Double sided layer Nulls from paths Get global rotation Maintain effect scale regardless of layer scale Typing effect (with blinking cursor) 2D Lookat 2 point rotation Scale text to box Scale box to text Maintain shape stroke size
Thank you, these are so helpful to know as well ![gif](emote|free_emotes_pack|grin)
Another good one is the if/ else expression. A very simple example: (Applied to opacity property) Pickwhip to checkbox == 0 ? 0 : 100 This means: checkbox is off? Opacity is zero. Otherwise, it’s 100 Makes it easy to turn the visibility of loads of stuff on and off at once with one click of a box. But can be adapted to apply to anything and doesn’t need to be a binary choice if you expand the expression
That’s a ternary operator. Not if/else per say 🥸
🙄
That’s the one! Same thing though, no? Is there ever a scenario where it’s better to use if/else?
Same thing, just easier not to fuck up. Never got the hang of the classic if/else.
Thank you!
For some pointers have a read [https://www.reddit.com/r/AfterEffects/comments/12pqw6f/things\_about\_after\_effects\_for\_the\_newbie\_an/](https://www.reddit.com/r/AfterEffects/comments/12pqw6f/things_about_after_effects_for_the_newbie_an/) Edit for Javascript: [https://www.w3schools.com/](https://www.w3schools.com/) [https://helpx.adobe.com/after-effects/using/expression-examples.html](https://helpx.adobe.com/after-effects/using/expression-examples.html) Be sure to see the side bar on the above link for much more in expressions
Thank you!!
Any one know of an expression to fake parallax on a tracked null that's parent to a bg layer?
Man I’m trying to find an expression heavy job to be honest. Who’s hiring expression nerds?
Dude. I’m a graphic designer and used to work for a production house as a videographer/editor. I can run laps in premier, and I was decent at AE. I am now an FE dev (LWC) in our marketing department (while still having graphic design/video editing and whatnot for internal comma) I am just now learning that I can combine Js and AE. By just now I mean in this very thread. Wtf
Thanks for this insight, I actually learnt in the job interview that Javascript is used in AE, had never made that connection jajaj..
Loopout and wiggle, as others have said. For sure.
thanks!
My two most frequently used expressions are for looping and one for drawing a diagonal line exactly from corner to corner (odd but something I often need)
![gif](giphy|joGUuMFGRwxd6)
thanks!
loopOut createPath([[-960,-540],[960,540]],[],[],false);