3

I've built an arrow that is controlled by two nulls - one at the start point and one at the end point. Using some trigonometry in some expressions, it works. When I move the nulls, the arrow resizes appropriately.

But when I try to parent one of the nulls to another object (like another null, or a shape layer), the null position jumps. And even after parenting, the parent null can't move the child null.. Any ideas?

video:

Below are snippets of the controlling code, based on some scripts by others that I found online.

arrowlength controlled by

CellTower = thisComp.layer("startpoint").transform.position;
Target = thisComp.layer("endpoint").transform.position;
sizefactor = 100/(effect("ArrowSize")("Slider"));
BeamLength = (length(CellTower, Target)*sizefactor)-150;
[BeamLength]

rotation of the arrow controlled by

CellTower=thisComp.layer("startpoint").transform.position;
Target=thisComp.layer("endpoint").transform.position;

// Find the length of side a
SideA = sub(CellTower, Target)[1];

// Find the length of side b
SideB = sub(CellTower, Target)[0];

//Find the Angle between them
-1*(270-(radiansToDegrees(Math.atan2(SideA, SideB))+180));

1 Answer 1

1

I think the problem there is that the expression is using the position value for the null. As you know when you parent a layer to another layer its position becomes relative to its parent. So if for example you have a null at [960,540] and you parent it to a layer whose position is also [960,540] the null's position now becomes [0,0]. This means that any expressions that use that value now are seeing [0,0] instead of [960,540].

So you need to feed the null's absolute position in world space to the expression. This is where the mysterious Layer Space Transform functions come into play.

Change the parts of the expression that have the null's position from

CellTower=thisComp.layer("startpoint").transform.position;

to

startPoint = thisComp.layer("startpoint"); 
//use a variable just to make the next line easier to understand
CellTower=startPoint.toWorld(startPoint.anchorPoint);

What that is doing is translating a point as seen from the relative coordinates of the layer startPoint to the world coordinates of the comp. The point that we're giving it to translate is startPoint's anchor point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.