Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Inertial bounce with clamp

  • Inertial bounce with clamp

    Posted by Andres Torres on September 2, 2013 at 7:49 pm

    I’m using the classic inertial bounce expression on position and rotation properties, but want to clamp the max value to the value of the second keyframe. It would be like the layer hits a wall or rotates against a wall. I’ve found a solution or two, but nothing that seems to work universally without breaking.

    Thanks,
    Andrés

    amp = .1;
    freq = 3.0;
    decay = 9.0;

    n = 0;
    if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time){
    n--;
    }}
    if (n == 0){ t = 0;
    }else{
    t = time - key(n).time;
    }
    if (n > 0 && t < 1){
    v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
    value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
    }else{value}

    Andres Torres replied 12 years, 11 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    September 2, 2013 at 7:55 pm
  • Andres Torres

    September 2, 2013 at 8:52 pm

    I’ve been trying this one from your site, but it behaves so different than my initial expression no matter how I play with my sliders for the variables. How would we keep my initial expression, but with a clamp on the second keyframe?

    e = .7;
    g = 5000;
    nMax = 9;

    n = 0;
    if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time) n--;
    }
    if (n > 0){
    t = time - key(n).time;
    v = -velocityAtTime(key(n).time - .001)*e;
    vl = length(v);
    if (value instanceof Array){
    vu = (vl > 0) ? normalize(v) : [0,0,0];
    }else{
    vu = (v < 0) ? -1 : 1;
    }
    tCur = 0;
    segDur = 2*vl/g;
    tNext = segDur;
    nb = 1; // number of bounces
    while (tNext < t && nb <= nMax){
    vl *= e;
    segDur *= e;
    tCur = tNext;
    tNext += segDur;
    nb++
    }
    if(nb <= nMax){
    delta = t - tCur;
    value + vu*delta*(vl - g*delta/2);
    }else{
    value
    }
    }else
    value

  • Andres Torres

    September 2, 2013 at 9:42 pm

    I actually found a previous post. Does this seem logical (I added an amp factor with a slider)?

    // https://forums.creativecow.net/thread/227/18170

    freq = effect("Freq")("Slider");
    decay = effect("Decay")("Slider");

    n = 0;
    p = thisProperty

    if (p.numKeys > 0){
    n = p.nearestKey(time).index;
    if (p.key(n).time > time) n--
    }

    if (n > 0){
    t = time - p.key(n).time;
    amp = p.velocityAtTime(p.key(n).time - .001)*effect("Amp")("Slider");

    w = freq*Math.PI*2;
    amp *= Math.floor(t*freq*2)%2 ? 1 : -1; value + amp* Math.sin(t*w)/Math.exp(decay*t)/w
    }else{
    value
    }

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