ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

confused about parenting (!) toWorld doesn't fix things

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
rob mcgowan
confused about parenting (!) toWorld doesn't fix things
on Feb 21, 2017 at 9:38:29 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?


//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];
return l;

Return to posts index

rob mcgowan
Re: confused about parenting (!) toWorld doesn't fix things
on Feb 21, 2017 at 9:56:49 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...

Return to posts index

Dan Ebberts
Re: confused about parenting (!) toWorld doesn't fix things
on Feb 21, 2017 at 10:39:46 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));


Return to posts index

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