top of page

Bounce Expression

This expression creates a bounce effect based on the velocity at the keyframe, with configurable amplitude, frequency, and decay values.

Background Line UI

Time Based Animation, Bounce Expression, Dynamic

18.6K

amp = 0.1; // Amplitude (Bounce height)
freq = 2.0; // Frequency (Bounce speed)
decay = 5.0; // Decay (Bounce fading speed)
n = 0; // Keyframe index
time_max = 4; // Maximum duration for bounce (after keyframe)

if (numKeys > 0) { // If there are keyframes
n = nearestKey(time).index; // Get nearest keyframe index
if (key(n).time > time) { // If the nearest keyframe is in the future
n--; // Go to the previous keyframe
}
}

if (n == 0) {
t = 0; // No bounce before the first keyframe
} else {
t = time - key(n).time; // Time since the last keyframe
}

if (n > 0 && t < time_max) { // If there's a keyframe and the bounce is within time limit
v = velocityAtTime(key(n).time - thisComp.frameDuration/10); // Get the velocity at keyframe
value + v * amp * Math.sin(freq * t * 2 * Math.PI) / Math.exp(decay * t); // Apply the bounce
} else {
value; // No bounce after the time limit
}
Imagine animating a ball falling to the ground, and you want it to bounce. Apply the bounce expression to the Position property of the ball layer. By adjusting the Amplitude (height of the bounce), Frequency (speed of the bounce), and Decay (how quickly the bounce fades), you can create a realistic bounce effect.
bottom of page