Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Compensate for a parent’s orientation when using lookAt() function

Tagged: 

  • Compensate for a parent’s orientation when using lookAt() function

    Posted by Reuben Lara on December 10, 2021 at 5:37 pm

    Hello! Im using the lookAt() function to point Shape1 to Shape2. This works fine unless Shape1 is itself parented to another shape who’s orientation is anything but 0,0,0. Here’s the expression I’m currently using:

    target = thisComp.layer("Star 2");
    look=lookAt(thisLayer.toWorld(transform.anchorPoint), target.toWorld(target.anchorPoint));
    [look[0],look[1]+180,look[2]]

    The 180° offset compensates for the default lookAt() result which always seems to offset the Y axis by 180°. I’ve tried every calculation I know of to compensate for the parent’s orientation but I believe the math is beyond me! Anyone able to solve this? Here’s a visual explanation of what I’m referring to:

    ScreenRecording

    And here’s a link to the file for testing

    Thank you!

    Reuben Lara replied 4 years, 6 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    December 10, 2021 at 8:24 pm

    Try this:

    //LOOKING AT: Star 2

    target = thisComp.layer("Star 2");

    p1 = fromWorld(thisLayer.toWorld(transform.anchorPoint));

    p2 = fromWorld(target.toWorld(target.anchorPoint));

    look=lookAt(p1,p2);

    [look[0],look[1]+180,look[2]]

  • Reuben Lara

    December 10, 2021 at 8:26 pm

    Amazing, thank you!!

  • Reuben Lara

    December 10, 2021 at 10:43 pm

    Hey Dan: why is the result of the expression cumulative to any values that may have already been in the orientation fields? For example, if I scrub either the x,y, or z values to anything other than 0,0,0 it seems to offset the expression’s calculation. Should any expression’s result override the property’s values by default? Are there any expression methods that will force an override?

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