I am definitely a beginner when it comes to expressions.
I am currently using a "bounce" expression on the position parameter of some objects as they come on screen. However, the next time they change positions, I don't want them to bounce. Every time a motion tween ends in a static position, the position expression gets applied and the stuff is moving around.
I'd like to be able to keyframe the expression so that it worked only when on the keyframes that it makes sense to affect.
amp = .05;
freq = 1;
decay = 7;
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
}
I got this script from somewhere online. The only thing I know how to manipulate are the initial values of amp, freq, and decay.
This version will only bounce at the 2nd keyframe:
amp = .05;
freq = 1;
decay = 7;
kf = 2; // only on 2nd keyframe
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n == kf){
t = time - key(n).time;
v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else
value
Dan
Thanks Dan.
I was hoping you would say, "Yeah, enable keyframing for the expression and then toggle the state on/off for specific frames."
I semi understand what you've done. I haven't gotten to the Expressions part of Lynda.com's After Effects Apprentice yet, so it will take me some time to figure out why this works, but I appreciate the solution!
- one man's difficult is another man's simple.
If you are looking for a general solution, use ExpressionTimeline: With a simple interface, you can make an expression only last for a specific range of time and even transition from one expression to another.
Here are some examples
From the beginning until frame 50 use the keyframed values and after frame 50 use a wiggle expression. ![]()
Smoothly transition from one expression to another. The first expression is active from frame 0 to 50, the second expression from frame 50 until the end. The smooth transition between the two expressions is 10 frames long and hence lasts from frame 45 to frame 54. With the expressions in this example, the layer first follows another layer (expression 1) until frame 45. Then until frame 54 it smoothly travels back to its own position and simultaneously starts to wiggle (expression 2). ![]()
This expression does'nt works in AE CS6. When applied it gives the error Message saying " invalid numeric result (divided by zero?) expression disabled. error occured at line 29". I usually use this expression a lot in AE CS5, but in CS6 showing error message. Pls can anyone help me....
Thanks in advance..
North America
Europe, Middle East and Africa
Asia Pacific