ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Position drives rotation

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Rich Cho
Position drives rotation
on May 24, 2011 at 4:29:37 pm

This seems like a simple thing to do but I just can't figure it out.
How do I write an expression that allows an object to rotate based on the position (X and Y) of another object.
Whenever I try this, it looks like this under rotation:

thisComp.layer("Solid 1").transform.position[0]
it only rotates when I move "Solid 1" in the X direction.
When I change it to
thisComp.layer("Solid 1").transform.position[1]
it only rotates when I move in the Y direction

I want the layer to rotate when you move "Solid 1" in the X OR the Y direction.

Return to posts index

Kevin Camp
Re: Position drives rotation
on May 24, 2011 at 4:48:27 pm

you need to use position as a vector (use both x and y). the length() function should do it...

try using this for the rotation:

length(thisComp.layer("Solid 1").transform.position)

Kevin Camp
Senior Designer

Return to posts index

Dan Ebberts
Re: Position drives rotation
on May 24, 2011 at 4:53:29 pm

I think you need a reference point to measure against. There are a couple of ways to do it. One is to just define a static point. This example uses the center of the comp:

center = [thisComp.width,thisComp.height]/2;
length(center,thisComp.layer("Solid 1").transform.position)

another way would be to compare the current position to where the layer was at time zero:

p = thisComp.layer("Solid 1").transform.position;

I haven't tested these, so beware of typos.


Return to posts index

Hayley Anderson
Re: Position drives rotation
on Dec 23, 2016 at 5:32:35 pm

Oh my god, Thank you Dan, I have been trying to find this expression for days!

Return to posts index

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