Unlink two layers after a certain time in After Effects 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 &lt;= 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?
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 &lt;= 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.