Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Continuous bounce

  • Posted by Kenji Takahashi on June 29, 2020 at 11:36 pm

    Hi I need help with the “famous” bounce expression. It`s interesting problem and I`m scratched out.

    Because frequence and decay are low ( I need it to be extra elastic) it only work for two keyframes.
    On keyframe 3 it snaps in its value and sometimes on keyframe 4, 5, 7, 9.. depending on the nearest key index I presume
    I`m trying valueAtTime but I`m limited with knowledge.

    I need my keyframes not to be precise but relative to previous inherited velocity.

    Thnx

    freq = 0.5;
    decay = 1;

    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

    Kenji Takahashi replied 6 years, 3 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    June 30, 2020 at 6:32 am

    See what this version does for you:


    freq = 0.5;
    decay = 1;
    val = value
    n = 0;
    if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time) n--;
    }
    if (n > 1){
    amp = velocityAtTime(key(n).time - .001);
    w = freq*Math.PI*2;
    for (i = 2; i <= n; i++){
    t = Math.min(time - key(i).time,10/decay);
    amp = velocityAtTime(key(i).time - .001);
    val += amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
    }
    }
    val

    Dan

  • Kenji Takahashi

    June 30, 2020 at 11:33 am

    Absolutely beautiful, thank you Dan,
    you sir are a gentleman and a scholar!

    It will take hours to see what you did there 🙂

  • Dan Ebberts

    June 30, 2020 at 12:47 pm

    This is slightly better:


    freq = 0.5;
    decay = 1;
    val = value
    n = 0;
    if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time) n--;
    }
    if (n > 1){
    w = freq*Math.PI*2;
    for (i = 2; i <= n; i++){
    t = time - key(i).time;
    if (t > 10/decay) continue;
    amp = velocityAtTime(key(i).time - .001);
    val += amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
    }
    }
    val

    Dan

  • Kenji Takahashi

    June 30, 2020 at 1:42 pm

    Yeah this one is cleaner.

    I was actually looking for solution to do this.

    I call it inertial animation. (or Ice animation ☺ )
    Basically with the tweak in frequency and decay I can make inertia in movement without null parenting, with fever keyframes and without tweaks to keyframe velocity.
    Example above was done with the code below and just easing first keyframe of movement. (animation must be done in linear fashion, forward, keyframe by keyframe. Just like pushing hockey puck on ice)

    Once again thanks Dan!

    freq = 0.001;
    decay = 0.6;
    val = value
    n = 0;
    if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time) n--;
    }
    if (n > 1){
    w = freq*Math.PI*2;
    for (i = 2; i &lt;= n; i++){
    t = time - key(i).time;
    if (t > 10/decay) continue;
    amp = velocityAtTime(key(i).time - .001);
    val += amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
    }
    }
    val

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