Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions confused about parenting (!) toWorld doesn’t fix things

  • confused about parenting (!) toWorld doesn’t fix things

    Posted by Rob Mcgowan on February 21, 2017 at 9:38 pm

    hi, I have 3 nulls named P1,P2 and P3 evenly distributed on my composition.

    P3 is parented to P2. P2 is parented to P1. P1 has no parent. All the nulls have scale 100%. All have anchorPoint [0,0].

    So I made a fn to calculate distances between them and although the nulls are evenly spaced on screen the two calculated distances are different by a factor of about 7. Using toWorld makes no difference. Changing from position to anchorPoint makes no difference.

    If I move P3 over P2 it’s position in the timeline goes to zero but it’s distance calculated by the fn goes up to about right. If I unparent P2 from P1 this too causes the distance to go up and again looks like it becomes right.

    Can anyone explain how to correctly get the world position of a chain of parented nulls in CS4?

    Thanks

    //this gives wildly wrong results (400 and 73)
    D12= getLength(p1.transform.position,toWorld(p2.transform.position));
    D23= getLength(toWorld(p2.transform.position),toWorld(p3.transform.position));

    //shouldn't have to do this since P1 is an orphan? and it isn't any better
    D12= getLength(toWorld(p1.transform.position),toWorld(p2.transform.position));

    //this gives zero for the distance
    D23= getLength(toWorld(p2.transform.anchorPoint),toWorld(p3.transform.anchorPoint));

    I've tested this...
    function getLength(p1,p2) {
    dx=p1[0] - p2[0];
    dy=p1[1] - p2[1];
    l=Math.sqrt(dx*dx+dy*dy);
    return l;
    }

    Dan Ebberts replied 9 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Rob Mcgowan

    February 21, 2017 at 9:56 pm

    OK, so I read Dan Ebberts cool steam engine page and I think I figured this out.

    I need the distance from P2 to p3 but P2 is parented to P2 so it’s in P2 coordinate space. SOOO the correct distance is just length([0,0] , P3.transform.position). Looks good so far…

  • Dan Ebberts

    February 21, 2017 at 10:39 pm

    This should work without regard to parenting:

    p1 = thisComp.layer(“P1”);
    p2 = thisComp.layer(“P2”);
    p3 = thisComp.layer(“P3”);
    d12 = length(p1.toWorld(p1.anchorPoint),p2.toWorld(p2.anchorPoint));
    d23 = length(p2.toWorld(p2.anchorPoint),p3.toWorld(p3.anchorPoint));

    Dan

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