Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions valueAtTime in both directions

  • valueAtTime in both directions

  • Julian Chojnacki

    December 3, 2022 at 3:16 am

    Hi folks,

    let’s say I have a keyframed animation that goes from 0 to -500 in Z space and back to 0 again and a layer that references that with valueAtTime and a -.1 delay.

    I want the delay to adapt to the change of direction, which works with this code:

    src=thisComp.layer(index-1)

    v=src.transform.position.velocity;

    let delay;

    if(v[2] >= 0) {delay = -.1} else {delay = .1};

    src.transform.position.valueAtTime(time-delay);

    Unfortunately, this generates two problems:

    1. On the first frame of the animation, which starts in the beginning of the comp, the position value jumps to -107.8, while it should be 0 since the animation it references is at 0 as well.
    2. One frame before the -500 keyframe and the direction switch, the delayed layers jump values, which makes it look choppy like a few frames have been skipped, due to the nature of the adaptive delay, which switches values abruptly.

    This code fixes the first problem:

    const src=thisComp.layer(index-1);

    const v = src.transform.position.velocity;

    let delay;

    if (time == 0){

    [value[0],value[1],value[2]];

    }else{

    (v[2] >= 0) ? delay = -.1 : delay = .1;

    src.transform.position.valueAtTime(time-delay);

    };

    …but the other persists.

    Any help would be fantastic 🙂

  • Julian Chojnacki

    December 3, 2022 at 4:01 am

    Update: cranking up the easing to 100 on the -500 keyframe fixed the problem…

  • Max Haller

    December 4, 2022 at 4:04 am

    see if this helps too

    const src = thisComp.layer(index-1);

    const v = src.transform.position.velocity;

    let delay;

    if (time == 0) {

    // Set the position to the initial value at time 0

    [value[0], value[1], value[2]];

    } else {

    // Check if the velocity is greater than or equal to 0

    if (v[2] >= 0) {

    // If the velocity is positive, check if the previous delay value was negative

    if (delay < 0) {

    // If the previous delay was negative, interpolate between the previous value and -0.1 to smooth out the transition

    delay = linear(time, time-thisComp.frameDuration, time, delay, -0.1);

    } else {

    // If the previous delay was not negative, set the delay to -0.1

    delay = -0.1;

    }

    } else {

    // If the velocity is negative, check if the previous delay value was positive

    if (delay > 0) {

    // If the previous delay was positive, interpolate between the previous value and 0.1 to smooth out the transition

    delay = linear(time, time-thisComp.frameDuration, time, delay, 0.1);

    } else {

    // If the previous delay was not positive, set the delay to 0.1

    delay = 0.1;

    }

    }

    // Use the calculated delay value to get the position value at the current time

    src.transform.position.valueAtTime(time - delay);

    }

  • Julian Chojnacki

    December 5, 2022 at 7:59 pm

    Max, you nailed it! Thanks for the proper education 😉

Viewing 1 - 4 of 4 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy