Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Using the loop expression to loop an expression

  • Using the loop expression to loop an expression

    Posted by Rob Nairn on October 6, 2016 at 12:55 am

    Hi all,

    I’ve been using some great code of Dan Ebberts for keyframe overshoot
    freq = 3;
    decay = 5;

    n = 0;
    if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time) n--;
    }
    if (n > 0){
    t = time - key(n).time;
    amp = velocityAtTime(key(n).time - .001);
    w = freq*Math.PI*2;
    value + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
    }else
    value

    It’s been working a treat, but I now want to to loop. I tried adding
    loopOut(type = "cycle", numKeyframes = 0)
    on the next line but it didn’t work.
    What should I do to make the keyframes repeat indefinitely?
    Thanks in advance.
    Cheers,
    Rob

    Rob Nairn replied 9 years, 7 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    October 6, 2016 at 3:36 am

    Instead of doing the overshoot at the last keyframe you want it to go back to the first keyframe? That doesn’t sound right.

    Dan

  • Rob Nairn

    October 6, 2016 at 3:59 am

    Hi Dan,

    I’m using it to give a repetitive pulse to an object, so it expands and contracts with the nice overshoot reduction in movement. I’d set a number of keyframes to generate the pulse, then duplicate the last keyframe a little after the pulse to set the frequency of the pulse.

    Cheers,
    Rob

  • Dan Ebberts

    October 6, 2016 at 4:12 am

    Try this:


    t = time;
    if (numKeys > 1){
    if (t > key(numKeys).time){
    t = key(1).time + (t - key(numKeys).time)%(key(numKeys).time - key(1).time);
    }
    }

    freq = 3;
    decay = 5;

    n = 0;
    if (numKeys > 0){
    n = nearestKey(t).index;
    if (key(n).time > t) n--;
    }
    if (n > 0){
    t2 = t - key(n).time;
    amp = velocityAtTime(key(n).time - .001);
    w = freq*Math.PI*2;
    valueAtTime(t) + amp*(Math.sin(t2*w)/Math.exp(decay*t2)/w);
    }else
    valueAtTime(t)

    Dan

  • Rob Nairn

    October 6, 2016 at 4:27 am

    Dan that works a treat! Thanks very much.

    But holy moly, thats more complicated than I’d hoped. If you have the time, could explain how it works and (forgive me if it’s a dumb question) but why just adding the standard loop expression doesn’t work?

    Cheers,
    Rob

  • Dan Ebberts

    October 6, 2016 at 6:36 am

    loopOut() loops the property’s keyframed value, not anything expression-generated. So by adding it to the end of another expression, you just overwrite the result of that expression with the loopOut() result.

    The first part of the new expression calculates the current loop time and plugs it into variable “t”, which is used in place of “time” in the original expression.

    Dan

  • Rob Nairn

    October 6, 2016 at 6:45 am

    That makes sense, thanks Dan!

    Cheers,
    Rob

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