0

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?

0

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.

  • 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! – Hec46 Mar 3 '17 at 22:41
  • 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. – stib Mar 5 '17 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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