Answers.Body: <p><code>valueAtTime</code> returns the keyframed value of the property, before any expression is applied.</p>
  
  <p>change it to:</p>
  
  <pre><code>p = thisComp.layer("Leader").transform.position;
  t = 1; // Stop following after 1 second
  if (time &lt;= t) {
      value + (p.value - p.valueAtTime(0));
  }
  else {
      value + (p.value.valueAtTime(t) - p.valueAtTime(0));
  }
  </code></pre>
  
  <p>or more simply:</p>
  
  <pre><code>p = thisComp.layer("Leader").transform.position;
  t = Math.min(time, 1); // time increases until it hits 1, then stays there
  value + (p.value.valueAtTime(t) - p.valueAtTime(0));
  </code></pre>
  
  <p>This avoids the <code>if()</code> statement which means it should evaluate faster.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-03T22:41:03.640Z
Answers.Text: Great! It works. I also like your simpler version, it works jut as good. Just in case, let me point out that it should be `p.valueAtTime(t)` instead of `p.value.valueAtTime(t)`, shouldn't it? Anyway, thanks a lot!
Answers.UserDisplayName: Hec46
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-05T22:30:53.650Z
Answers.Text: Interesting. I usually use `[property].valueAtTime()` rather than `[property].value.valueAtTime()`, it seems to work just as well for expressions, but you do need to use the second form for extendscript scripting.
Answers.UserDisplayName: stib
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-02T11:06:23.247Z
Answers.LastActivityDate: 2017-03-02T11:06:23.247Z
Answers.UserDisplayName: stib
Body: <p>In After Effects, I want to have a layer (let's call it <code>Leader</code>) that moves and another one (let's say <code>Follower</code>) that is linked to the first one, so it will have the same movement, but at a specific time (<code>t</code>) it should "unlink" from the first layer and stay in that position. I have tried the following:</p>
  
  <pre><code>p = thisComp.layer("Leader").transform.position;
  t = 1; // Stop following after 1 second
  if (time &lt;= t) {
      position = value + (p.value - p.valueAtTime(0));
  }
  else {
      valueAtTime(t - thisComp.frameDuration);
  }
  </code></pre>
  
  <p>But for some reason I don't understand, at time <code>t</code>, the <code>Follower</code> goes back to its original position instead of staying in the place in which it was "unlinked" from the <code>Leader</code>. What am I missing?</p>
  
Tags: <after-effects><after-effects-expressions>
Title: Unlink two layers after a certain time in After Effects
UserDisplayName: Hec46
ThreadText: # Unlink two layers after a certain time in After Effects
  
  (Asked by: username_0 on 2017-03-01)
  
  In After Effects, I want to have a layer (let's call it `Leader`) that moves and another one (let's say `Follower`) that is linked to the first one, so it will have the same movement, but at a specific time (`t`) it should "unlink" from the first layer and stay in that position. I have tried the following:
  
  ```
  p = thisComp.layer("Leader").transform.position;
  t = 1; // Stop following after 1 second
  if (time <= t) {
      position = value + (p.value - p.valueAtTime(0));
  }
  else {
      valueAtTime(t - thisComp.frameDuration);
  }
  
  ```
  
  But for some reason I don't understand, at time `t`, the `Follower` goes back to its original position instead of staying in the place in which it was "unlinked" from the `Leader`. What am I missing?
  
  **Tags:** after-effects, after-effects-expressions
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-03-02. Score: 0 | Accepted answer
  
  `valueAtTime` returns the keyframed value of the property, before any expression is applied.
  
  change it to:
  
  ```
  p = thisComp.layer("Leader").transform.position;
  t = 1; // Stop following after 1 second
  if (time <= t) {
      value + (p.value - p.valueAtTime(0));
  }
  else {
      value + (p.value.valueAtTime(t) - p.valueAtTime(0));
  }
  
  ```
  
  or more simply:
  
  ```
  p = thisComp.layer("Leader").transform.position;
  t = Math.min(time, 1); // time increases until it hits 1, then stays there
  value + (p.value.valueAtTime(t) - p.valueAtTime(0));
  
  ```
  
  This avoids the `if()` statement which means it should evaluate faster.
  
  > **Comments:**
  > **username_0**: Great! It works. I also like your simpler version, it works jut as good. Just in case, let me point out that it should be `p.valueAtTime(t)` instead of `p.value.valueAtTime(t)`, shouldn't it? Anyway, thanks a lot!  
  > **username_1**: Interesting. I usually use `[property].valueAtTime()` rather than `[property].value.valueAtTime()`, it seems to work just as well for expressions, but you do need to use the second form for extendscript scripting.  
  
  ---
  
  