ADOBE AFTER EFFECTS: Forum Expressions Tutorials Podcasts Creative Cloud

Rotation expression

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Gavin EdwardsRotation expression
by on Aug 27, 2013 at 4:37:57 pm

Hi there, i'm hoping someone can help me with this, i'm thinking a simple expression should work it out.

I have an object parented to a null situated a about 80pix away from it. I want to be able to rotate the null and for the object spin around it but to always remain upright.

Any clues greatly appreciated.

Return to posts index

mathew fullerRe: Rotation expression
by on Aug 27, 2013 at 5:25:00 pm

This generates perfect circular motion centered around the original position of the layer. I recommend that you map the radius and
cycle inputs to Expression Control sliders, and the phase input to an Expression Control angle.
Apply this expression to the position of the layer.

radius = 75; // the radius of the circle
cycle = 1; // number of seconds to complete a circle; higher value = slower
if(cycle ==0){cycle = 0.001;} //avoids a “divide by zero” error
phase = 27; // initial angle in degrees from bottom
reverse = 1; // 1 for ccw, -1 for cw
x = Math.sin( reverse * degrees_to_radians(time * 360 / cycle + phase));
y = Math.cos(degrees_to_radians(time * 360 / cycle + phase));
add(mul(radius, [x, y]), position)

My Work:

Return to posts index

mathew fullerRe: Rotation expression
by on Aug 27, 2013 at 5:26:18 pm

Apply this Expression to the Rotation channel of any layer you wish to control,
Set LookAt, below, to the name of the layer you wish the layer to look at.
If the controlled layer is not initially pointing straight up, enter an offset amount in degrees, below, to adjust the direction it is

LookAt = "ball"
offset = 0
diffx = position[0] - this_comp.layer(LookAt).position[0];
diffy = position[1] - this_comp.layer(LookAt).position[1];
if (diffx == 0) {
diffx = 1 }
sign = 1 + (-1 * (diffx / Math.abs(diffx))) * 90;
radians_to_degrees(Math.atan(diffy/diffx)) + sign + offset

My Work:

Return to posts index

Walter SoykaRe: Rotation expression
by on Aug 27, 2013 at 6:04:41 pm

This will need a semicolon at the end of the "offset = 0" line.

The super-simple way to offset rotation when one object is parented to another is to alt-click the child object's rotation property, type a minus, then drag the pickwhip to the parent object's rotation property.

You'll end up with something like this:


Not as robust as Matt's solutions, but works well for keeping children level while their parent rotates.

Walter Soyka
Principal & Designer at Keen Live
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
RenderBreak Blog - What I'm thinking when my workstation's thinking
Creative Cow Forum Host: Live & Stage Events

Return to posts index

Gavin EdwardsRe: Rotation expression
by on Aug 27, 2013 at 7:53:10 pm

Thankyou Walter, your super simple solution works good.

Thanks also Mathew, i'll check out those expressions too.

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2016 All Rights Reserved