Johnny G Junior's NoteBook Treasures: AfterFX Expression: Rotation driven by position

Saturday, April 25, 2009

AfterFX Expression: Rotation driven by position

While surfing the web, i run into many great resources that help make life a whole lot easier to live. For example this expression for after fx from creativecow.net.

Use this expression to figure out the spin rotation rate of a wheel compared to the movement(translations) of the BODY its attached to. EXAMPLE (car, tracker, wheelborrow, BIKE).





Alt Click on ROTATION to set an expression and add this.


d=width;
pi=Math.PI;
circ=d*pi;
rot = 360/circ;

movex=thisComp.layer("body").transform.position[0];
scaler=thisComp.layer("body".transform.scale[0]/100;

rot*movex/scaler;



Math is great - especially High School Math. circumference of a circle is circ = pie x diameter.



[pie = 3.14 (Math.PI), diameter = width = pixels]. rotation is for every (CIRC) we want it revolve 1 REVOLUTION (or 360 DEGREES).. Rotation = 360/circ * pixels traveled on x

The scaler variable comes in just incase you want to change the scale of an object without throwing off the script.

it whole equation is Rotation = (360/circ) * pixels traveled / scale.

[d, pi, circ, rot, movex, scaler] are all variables. They are just storage names that are referenced throughout the script.

[rot*movex/scaler] is the equation.

No comments: