Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Position drives rotation

  • Position drives rotation

    Posted by Rich Cho on May 24, 2011 at 4:29 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.

    Hayley Anderson replied 9 years, 8 months ago 4 Members · 3 Replies
  • 3 Replies
  • Kevin Camp

    May 24, 2011 at 4:48 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
    KCPQ, KMYQ & KRCW

  • Dan Ebberts

    May 24, 2011 at 4:53 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;
    length(p,p.valueAtTime(0))

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

    Dan

  • Hayley Anderson

    December 23, 2016 at 5:32 pm

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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy