Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › looping a keyframe animation after setting the keyframe using a slider

  • looping a keyframe animation after setting the keyframe using a slider

    Posted by Tom Greaves on October 19, 2020 at 2:48 pm

    I have two keyframes on the Evolution property, the second keyframe is set by the value of a slider.

    This is working, but i want the keyframes to loop, and carry on beyond the second keyframe.

    Whenever, and however i add loopOut() it breaks the part of the expression which sets the value of key(2) and it reverts to whatever i set it as last.

    I’m sure i’m missing something fundemental here in how the loopOut can’t work with the linear() maybe?

    Any help to get this looping would be appreciated!

    (P.S I don’t want to precomp the layer and loop the time-remapping, would like to keep it in the Evlotion property if possible)

    Here’s the expression, which works to set the second keyframe, without the loopOut()

    if (numKeys > 1){

    ctrl = thisComp.layer(“// controls”).effect(“Edges Animation Speed”)(“Slider”);

    t1 = key(1).time;

    t2 = key(2).time;

    v1 = 0;

    v2 = ctrl;

    linear((time), t1, t2, v1, v2);

    } else {

    value

    }

    How can i loop this?

    Thanks in advance.

    Dan Ebberts replied 5 years, 11 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    October 19, 2020 at 3:35 pm

    This should work:

    if (numKeys > 1){

    ctrl = thisComp.layer("// controls").effect("Edges Animation Speed")("Slider");

    t1 = key(1).time;

    t2 = key(2).time;

    v1 = 0;

    v2 = ctrl;

    t = time;

    if (t > t2){

    t = t1 + (t - t2)%(t2 - t1);

    }

    linear((t), t1, t2, v1, v2);

    } else {

    value

    }

  • Tom Greaves

    October 19, 2020 at 6:45 pm

    Dan, you’re a hero, that worked! Thank you!

    Would you mind explaining what is happening here:

    t = t1 + (t – t2)%(t2 – t1);

    Is it somehow forcing the order of playing the keyframes?

    Thanks again!

    Tom

  • Dan Ebberts

    October 19, 2020 at 9:00 pm

    Basically that line does a little modulo math (divide, but only keep the remainder) to calculate where between t1 and t2 the current time should be. So it creates the looping by translating any time beyond t2 to the appropriate time between t1 and t2.

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