Skip to main content
Participant
May 25, 2023
Answered

Expression in Transform effect properties

  • May 25, 2023
  • 2 replies
  • 670 views

Hello,

By any chance could someone explain the following expression to me briefly, telling me what it does and how I can adjust certain values and what those adjustments will do, I want to keep it as a template. I found it in a project file I bought from someone, so I can see what it does, I just want to be able to adjust it. Also, I noticed keyframes used and dont know how they'd be set either. The expression was placed on the 'Rotation' and 'Position' properties of the 'Transform' effect. Thanks guys.

 

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 = .1;
freq =3.1;
decay = 7;
value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
value;
}

This topic has been closed for replies.
Correct answer Dan Ebberts

It's a overshoot expression with decaying oscillation. At each keyframe it overshoots the animation coming into the keyframe and oscillates until it dies out. The amplitude of the overshoot is controled by amp, the frequency of oscillation by freq, and the speed of the decay by decay. It requires keyframes to do anything, as it's just overshooting the animation at each keyframe (so keyframes with ease in won't work because incoming velocity will be zero). There's a better version here that automatically matches the amplitude to the incoming animation:

http://www.motionscript.com/articles/bounce-and-overshoot.html#kf-overshoot

2 replies

Community Expert
May 25, 2023

The expression starts off looking for keyframes. 

The next line part of the expression looks for the time of the nearest keyframe, and it always looks forward. 

The next part looks at the time between keyframes and checks to see how fast the layer is moving.

 

Now a numeric value is assigned to the Amplitude, the Frequency, and the Delay for the trigonometry part of the calculation that sets up a decaying bounce to a stop. Change the numbers, and you get a different decaying pattern.

 

It's pretty simple. It would work for a bouncing ball. Animate a sphere from the top to the bottom of a composition over a half-second. The time it takes to stop bouncing is controlled by the Decay value. The size of the bounce is controlled by the Amplitude, and the time between bounces is controlled by the Frequency.

PT MatikAuthor
Participant
May 25, 2023

Thanks very much for the extra info.

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
May 25, 2023

It's a overshoot expression with decaying oscillation. At each keyframe it overshoots the animation coming into the keyframe and oscillates until it dies out. The amplitude of the overshoot is controled by amp, the frequency of oscillation by freq, and the speed of the decay by decay. It requires keyframes to do anything, as it's just overshooting the animation at each keyframe (so keyframes with ease in won't work because incoming velocity will be zero). There's a better version here that automatically matches the amplitude to the incoming animation:

http://www.motionscript.com/articles/bounce-and-overshoot.html#kf-overshoot