top of page
Search

# Bounce Expression in After Effects - After Effects Quick Tips and Tricks

```amp = .1;
freq = 2.0;
decay = 5.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}

```

##### This expression defines the behavior of a sinusoidal animation or visual effect in Adobe After Effects. Let's break it down line by line:

1. amp = .1; This line sets the amplitude ("amp") of the sine wave to 0.1.

2. freq = 2.0; This line sets the frequency ("freq") of the sine wave to 2.0.

3. decay = 5.0; This line sets the decay rate ("decay") of the sine wave to 5.0.

4. n = 0; This line initializes the frame number ("n") to 0.

5. time_max = 4; This line sets the maximum time value ("time_max") to 4.

6. if (numKeys > 0){ This line checks whether there are any keyframes in the timeline. If there are no keyframes, the expression will not apply.

7. n = nearestKey(time).index; This line sets the frame number ("n") to the index of the nearest keyframe in the timeline.

8. if (key(n).time > time){ This line checks whether the time of the keyframe at frame number "n" is greater than the current time. If it is, the expression will use the previous keyframe instead.

9. n--; This line decrements the frame number ("n") to use the previous keyframe.

10. if (n == 0){ t = 0; This line checks whether the frame number is 0 (i.e., there are no keyframes). If there are no keyframes, the time value ("t") is set to 0.

11. }else{ This line begins the "else" block, which is executed if there is at least one keyframe.

12. t = time - key(n).time; This line calculates the time since the previous keyframe ("t") by subtracting the time of the previous keyframe from the current time.

13. if (n > 0 && t < time_max){ This line checks whether the frame number is greater than 0 and the time since the previous keyframe is less than the maximum time value. If these conditions are met, the expression will apply.

14. v = velocityAtTime(key(n).time - thisComp.frameDuration/10); This line calculates the velocity ("v") at the previous keyframe by subtracting one frame duration from the time of the previous keyframe and using the "velocityAtTime" function.

15. value + vampMath.sin(freqt2Math.PI)/Math.exp(decayt); This line calculates the value of the sine wave at the current time by multiplying the velocity, amplitude, and sine wave function (which is a function of the frequency and time), and dividing by the exponential decay rate. This value is added to the current value of the animation or effect.

16. }else{value} This line ends the "if" block and sets the value to the current value if the conditions in line 13 are not met.

Overall, this expression creates a sinusoidal animation or visual effect that varies in amplitude, frequency, and decay rate over time, and is affected by the velocity of the animation or effect at each keyframe. The expression checks for keyframes in the timeline and uses the previous keyframe's velocity to determine the behavior of the sine wave between keyframes.
12,523 views

See All
bottom of page