Answers.Body: <p>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].</p>
  
  <p>So you need to feed the null's absolute position in world space to the expression. This is where the mysterious <strong>Layer Space Transform</strong> functions come into play.</p>
  
  <p>Change the parts of the expression that have the null's position from</p>
  
  <pre><code>CellTower=thisComp.layer("startpoint").transform.position;
  </code></pre>
  
  <p>to </p>
  
  <pre><code>startPoint = thisComp.layer("startpoint"); 
  //use a variable just to make the next line easier to understand
  CellTower=startPoint.toWorld(startPoint.anchorPoint);
  </code></pre>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-08T23:08:07.537Z
Answers.LastActivityDate: 2016-02-08T23:08:07.537Z
Answers.UserDisplayName: stib
Body: <p>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.</p>
  
  <p>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?</p>
  
  <p>video:
  <div class="youtube-embed"><div>
                  <iframe width="640px" height="395px" src="https://www.youtube.com/embed/RPW8DrsX7Y0?start=0"></iframe>
              </div></div></p>
  
  <p>Below are snippets of the controlling code, based on some <a href="https://forums.creativecow.net/thread/227/6984" rel="nofollow">scripts by others</a> that I found online.</p>
  
  <p>arrowlength controlled by</p>
  
  <pre><code>CellTower = thisComp.layer("startpoint").transform.position;
  Target = thisComp.layer("endpoint").transform.position;
  sizefactor = 100/(effect("ArrowSize")("Slider"));
  BeamLength = (length(CellTower, Target)*sizefactor)-150;
  [BeamLength]
  </code></pre>
  
  <p>rotation of the arrow controlled by</p>
  
  <pre><code>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));
  </code></pre>
  
Tags: <after-effects><after-effects-expressions>
Title: Parenting a null causes unexpected results
UserDisplayName: tomh
ThreadText: # Parenting a null causes unexpected results
  
  (Asked by: username_0 on 2016-02-08)
  
  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](https://forums.creativecow.net/thread/227/6984) 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));
  
  ```
  
  **Tags:** after-effects, after-effects-expressions
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-08. Score: 1 | Accepted answer
  
  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.
  
  
  ---
  
  