Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions (De)Accelerating a loop expression…

  • (De)Accelerating a loop expression…

    Posted by Martijn De schrijver on August 20, 2012 at 2:57 pm

    Hi,

    After looking for quite some time on several resources, I can’t figure this one out.
    Sorry if this is simple, but I’m not that experienced yet with expressions.

    I have an object that moves along a path that I pasted in from Illustrator. I’ve made
    the object loop, and all of that works fine. But I would like to have it ‘deaccelerate’ exponentially,
    so that it’s looping super fast and over a given amount of time would slow down to come to a halt.

    Is there any way to do this through expressions?
    (Or can I edit the property in the ‘expression result’ Graph Editor?)

    Thanks so much!

    Alex Ezorsky replied 10 years, 3 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    August 20, 2012 at 7:41 pm

    When you paste a path into the Position property, you should get a two-second animation. You can then add a slider and keyframe it to control the speed. A slider value of 1 will keep the loop at 2 seconds, a value of 2 will make it twice as fast, 0.5 half as fast, etc. Then use this expression instead of your loopOut() expression:


    spd = effect("Slider Control")("Slider");
    n = spd.numKeys;
    if (n > 0 && spd.key(1).time < time){
    accum = spd.key(1).value*(spd.key(1).time - inPoint);
    for (i = 2; i <= n; i++){
    if (spd.key(i).time > time) break;
    k1 = spd.key(i-1);
    k2 = spd.key(i);
    accum += (k1.value + k2.value)*(k2.time - k1.time)/2;
    }
    accum += (spd.value + spd.key(i-1).value)*(time - spd.key(i-1).time)/2;
    }else{
    accum = spd.value*(time - inPoint);
    }

    if (numKeys > 1){
    d = key(numKeys).time - key(1).time;
    t = (accum - key(1).time)%d;
    valueAtTime (key(1).time + t);
    }else
    value

    This is basically the speed-control expression described here:

    https://www.motionscript.com/articles/speed-control.html#linear

    combined with a “roll-your-own” loopOut() expression.

    Dan

  • Martijn De schrijver

    August 21, 2012 at 8:48 am

    Wow this works beautifully already!!

    Since I wanted it to go super fast first, and then slow down to nothing, I tried to keyframe the
    slider from 100 to 0 at first, but that seemed weird. The maximum for continuous movement seemed 24-0.

    When I had it slow down from 100, it slowed down and went the other direction at 96 and every 24 interval inbetween (72,48,24).

    Any idea if I could fix this? (Out of curiosity, because 24 is already pretty fast!)

    Thanks so much,

    Martijn

  • Dan Ebberts

    August 21, 2012 at 1:13 pm

    Is your comp 24fps? If so, my guess would be that as your loops per second approachs a multiple of the frame rate you would experience a strobe effect similar to the spokes of a wagon wheel seeming to go backwards on film as the wagon speeds up. So basically, your object makes almost (but not quite) a whole number of loops from one frame to the next and appears to back up.

    Dan

  • Martijn De schrijver

    August 21, 2012 at 1:27 pm

    The script’s that nifty, huh? Super!
    I was working at 25fps, but it looks like you hit the nail on the head.

    So thanks so much! From the amount of people you help
    on this forum, it looks like your quite the savior!

    You sure were for me!

    Thanks again

  • Alex Ezorsky

    May 31, 2016 at 6:02 pm

    This script did exactly what I needed for my characters ability to come to a slow stop in a walking loop. But what if I want them to slowly start up again? It seems like once you add the second keyframe it kills all activity afterwards.

    Thanks!

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