After Effects Expression - Inertial Rotation

This expression will rotate the layer according to its speed and it will create a bounce on the rotation when the layer stops suddenly.

Apply this code on the Layer's Rotation:

let amp = 2.0; //Sets the angle that the layer will rotate on the spring animation
let freq = 2.0; //Sets the velocity that the spring animation will have
let decay = 4.0; //How long the spring animation lasts
let rotateOnMovement = 42; //Maximum angle that the layer will rotate when it's moving
let useAxis = 0; // 0 will use the speed of the X axis and 1 will use the speed of the Y axis
let timeBeforeKey = thisComp.frameDuration/10;
let refValue = position;

if (refValue.velocity[useAxis] != 0) {
	linear(refValue.velocity[useAxis], -3000, 3000, -rotateOnMovement, rotateOnMovement);
} else {
	let n = 0;
	if (refValue.numKeys > 0) {
		n = refValue.nearestKey(time).index;
		if (refValue.key(n).time > time) { n--; }
	}
	if (n == 0) {
		t = 0;
	} else {
		t = time - refValue.key(n).time;
	}
	if (n > 0 && t < 1) {
		let v = refValue.velocityAtTime(refValue.key(n).time - timeBeforeKey)[useAxis];
		value - (v*(amp/100)*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t));
	} else {
		value;
	}
}


/*
Expression by Francisco Giordano, January 2021.
Based on Intertial Bounce Expression by Animoplex - https://gist.github.com/animoplex/aafd6a157282351c8dfeea385d969ef2
Free for personal use and commercial use.
Instagram @ae.fran.giodano - frangiordano96@gmail.com
*/

Last updated