Answers.Body: <p>From <a href="https://www.youtube.com/watch?v=n4j0vqUCBDM" rel="nofollow noreferrer">this tutorial</a>, if you parent one layer's position to another's position, you can use an expression like this to follow the first layer:</p>
  <pre><code>thisComp.layer(&quot;red star&quot;).transform.position.valueAtTime(time-0.5)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-26T09:01:25.093Z
Answers.Text: That would work great if I wanted them to follow the exact same path, but that's not quite what I'm looking for. The following layer should be moving towards the layer being followed independent of that actual layer's movement.
Answers.UserDisplayName: JoaoB
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-21T15:20:39.373Z
Answers.LastActivityDate: 2023-04-21T15:20:39.373Z
Answers.UserDisplayName: tomh
Body: <p>I have the following expression on the position of a layer that makes it follow another layer(FollowNull). Basically, I set an initial position with a PointController and the expression does it's magic.</p>
  <pre><code>s = effect(&quot;Speed&quot;)(&quot;Slider&quot;);
  p1 = effect(&quot;InitialPosition&quot;)(&quot;Point&quot;);
  p2 = thisComp.layer(&quot;FollowNull&quot;).transform.position;
  d = (length(p1,p2))/s;
  t = (time - inPoint)%d;
  
  linear(t, 0, d, p1, p2);
  </code></pre>
  <p>The problem is when I actually start moving (keyframing) the FollowNull layer, the speed changes. I'm assuming it is because the distance between both layers is only calculated once, so the travel time stays the same, even if one layer is going away from the other.</p>
  <p>Any idea how I can fix this behaviour?</p>
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-21T15:12:43.257Z
Comments.Text: https://www.youtube.com/watch?v=n4j0vqUCBDM
Comments.UserDisplayName: tomh
Tags: <after-effects><after-effects-expressions>
Title: Making an After Effects layer follow another one at constant speed
UserDisplayName: JoaoB
ThreadText: # Making an After Effects layer follow another one at constant speed
  
  (Asked by: username_0 on 2023-04-20)
  
  I have the following expression on the position of a layer that makes it follow another layer(FollowNull). Basically, I set an initial position with a PointController and the expression does it's magic.
  
  ```
  s = effect("Speed")("Slider");
  p1 = effect("InitialPosition")("Point");
  p2 = thisComp.layer("FollowNull").transform.position;
  d = (length(p1,p2))/s;
  t = (time - inPoint)%d;
  
  linear(t, 0, d, p1, p2);
  
  ```
  
  The problem is when I actually start moving (keyframing) the FollowNull layer, the speed changes. I'm assuming it is because the distance between both layers is only calculated once, so the travel time stays the same, even if one layer is going away from the other.
  
  Any idea how I can fix this behaviour?
  
  Thanks!
  
  **Tags:** after-effects, after-effects-expressions
  
  > **Comments:**
  > **username_1**: https://www.youtube.com/watch?v=n4j0vqUCBDM  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-04-21. Score: 0
  
  From [this tutorial](https://www.youtube.com/watch?v=n4j0vqUCBDM), if you parent one layer's position to another's position, you can use an expression like this to follow the first layer:
  
  ```
  thisComp.layer("red star").transform.position.valueAtTime(time-0.5)
  
  ```
  
  > **Comments:**
  > **username_0**: That would work great if I wanted them to follow the exact same path, but that's not quite what I'm looking for. The following layer should be moving towards the layer being followed independent of that actual layer's movement.  
  
  ---
  
  