Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions orient one partended layer towards another parented layer

  • orient one partended layer towards another parented layer

    Posted by Neil Stubbings on August 25, 2009 at 5:24 pm

    i dug deep in the various forums to find something that helps. I did find this expression, but this only works for non parented layers:

    delta = position – thisComp.layer(“Null 1”).position;
    radians_to_degrees(Math.atan2(delta[1],delta[0])) + 90

    I tried to incorporate this expression (which gets world coordinates of parented layers)

    L = thisComp.layer(“Null 1”);
    L.toWorld(L.anchorPoint)

    but I was not get something working, because heck, i hardly have any expreience in writing expresions myself.

    Can one of you expression masterminds solve this?

    regards
    Neil


    Neil Stubbings
    Graphic Design | Motion Graphics
    https://www.stubbings.ch

    Michael Szalapski replied 16 years ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    August 25, 2009 at 6:58 pm

    Try this:

    L = thisComp.layer(“other parented layer”);
    v1 = normalize(L.toWorld(L.anchorPoint) – toWorld(anchorPoint));
    v2 = toWorldVec([1,0,0]);

    -radiansToDegrees(Math.acos(dot(v1,v2)));

    You might have to add or subtract 90 degrees or add 180 degrees to get it to point in the right direction, depending on how you have things set up

    Dan

  • Neil Stubbings

    August 25, 2009 at 7:49 pm

    oh man thanks alot dan, your wizardness is amazing!


    Neil Stubbings
    Graphic Design | Motion Graphics
    https://www.stubbings.ch

  • Neil Stubbings

    August 26, 2009 at 9:37 am

    hmm, gives me an invalid numeric result (divide by zero) on line 5

    any ideas?


    Neil Stubbings
    Graphic Design | Motion Graphics
    https://www.stubbings.ch

  • Dan Ebberts

    August 26, 2009 at 2:43 pm

    The only way I can think of that happening is if you let both layers occupy the same position, where the notion of one layer pointing at the other really has no meaning. This should defend against the error, but you may get bizzare results if you let the layers line up like that.

    L = thisComp.layer(“other parented layer”);
    v1 = L.toWorld(L.anchorPoint) – toWorld(anchorPoint);
    if (length(v1) < .0001){ value }else{ v2 = toWorldVec([1,0,0]); -radiansToDegrees(Math.acos(dot(normalize(v1),v2))); } Dan

  • Michael Szalapski

    April 22, 2010 at 2:48 pm

    In case anybody runs across this in the future and you find that your layer doesn’t quite follow where it’s supposed to; it may have to do with numbers of rotation degrees running into and out of the negative numbers. (I think…that’s what mine appeared to be doing.)
    Simply put a positive number on the actual rotation value of your layer (I did 90) then subtract it in the expression. Life is now golden.

    BTW, Dan, you saved me much heartache and brainache with this one.

    – The Great Szalam
    (The ‘Great’ stands for ‘Not So Great, in fact, Extremely Humble’)

    No trees were harmed in the creation of this message, but several thousand electrons were mildly inconvenienced.

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