Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scale Expression with inertia bounce – start from zero

  • Scale Expression with inertia bounce – start from zero

    Posted by Justin Alexander on October 21, 2011 at 7:42 am

    Hi everyone,

    I have been using these forums for a long while and found them to be immeasurably helpful.

    What I am trying to do now is get a layer to scale in and scale out at its in and out points, along with a bit of an inertia spring.

    I have used one of Dan Ebberts scripts from one of the posts here and modified it a bit to work at in and out points.

    The problem I am having is that the layer needs to be constantly re-sized to get somewhat reasonable results. Most of the time it bounces out OK although it never seems to really get to 0% scale. The in point is the one that doesn’t work properly though. Rarely can I get it to start at 0% scale. I have to have the layer scaled to the right size and tweak the ‘Scale’ setting in the expression. I normally have the variable set to sliders but have replaced them with my default settings here for easier dissecting.

    I have the following script on a solid scaled at 40% in a 1050 x 576 comp. Solid was made comp size as I want this to work at any scale.

    What I want to accomplish is to have the layer start at 0& scale and ramp up to whatever I set before applying the script. Then have a bit of inertia bounce that can be adjusted for intensity and length. At the minute the inertia bounce is working beautifully, I just need the scale to start and finish a 0%.

    Then I want to be able to save it as a preset and have it save me hours of time over the next couple of years.

    Really hope that I have made sense and that someone is able to tell me where I have gone wrong.

    Regards

    Justin Alexander

    PS: Thanks to Roland R. Kahlenberg for pointing me to the correct forum for this issue

    S =100; // Scale
    A =20; // Amplitude
    F =20; // Fequency
    to = outPoint - time;
    ti = time - inPoint;
    inTrans = x=S*(1-Math.exp(-A*ti)*Math.cos(F*ti));
    outTrans = y=S*(1-Math.exp(-A*to)*Math.cos(F*to));
    value+ [inTrans,inTrans] + [outTrans,outTrans];

    Scott Green replied 11 years, 4 months ago 5 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    October 21, 2011 at 4:31 pm

    I’m not sure this is what you’re describing, but give it a try and see if it’s close:


    rate = 500;
    rampDur = value[0]/rate;
    freq = 3;
    decay = 5;
    w = freq*Math.PI*2;

    if (time < (inPoint+outPoint)/2){
    if (time < (inPoint + rampDur)){
    s = linear(time,inPoint,inPoint+rampDur,0,value[0]);
    }else{
    t = time - (inPoint+rampDur);
    s = value[0] + rate*Math.sin(t*w)/Math.exp(t*decay)/w;
    }
    }else{
    if (time > (outPoint - rampDur)){
    s = linear(time,outPoint-rampDur,outPoint,value[0],0);
    }else{
    t = (outPoint - rampDur) - time;
    s = value[0] + rate*Math.sin(t*w)/Math.exp(t*decay)/w;
    }
    }
    [s,s]

    Dan

  • Justin Alexander

    October 21, 2011 at 9:19 pm

    Hi Dan,

    Thank you so much for solving my problem.

    That is absolutely what I was after.

    This will save me a heap of time over the next few yeas.

    Much appreciated

    Justin

  • Geoffrey Amend

    February 19, 2013 at 5:15 pm

    Hi. I’m researching how to get a star shape and a possibly a text layer (not sure if I’m going to have them connected or not) to “pop” up, hold for a second, so we can read the text and then pop back down to start position.

    I like this bounce action. Thank you for the expression.

    I put it on the P layer of the contents transform section…Should I put it on the P section of the Poystar path instead?

    Either way. I’m wondering how to control the start/stop points and also to get the shape to bounce back to position after holding….

    Any further assistance is greatly appreciated. Thank you very much.

    rate = 500;
    rampDur = value[0]/rate;
    freq = 3;
    decay = 5;
    w = freq*Math.PI*2;

    if (time &lt; (inPoint+outPoint)/2){
    if (time &lt; (inPoint + rampDur)){
    s = linear(time,inPoint,inPoint+rampDur,0,value[0]);
    }else{
    t = time - (inPoint+rampDur);
    s = value[0] + rate*Math.sin(t*w)/Math.exp(t*decay)/w;
    }
    }else{
    if (time > (outPoint - rampDur)){
    s = linear(time,outPoint-rampDur,outPoint,value[0],0);
    }else{
    t = (outPoint - rampDur) - time;
    s = value[0] + rate*Math.sin(t*w)/Math.exp(t*decay)/w;
    }
    }
    [s,s]

    Thank you!

  • Geoffrey Amend

    February 19, 2013 at 6:16 pm

    Figured it out with another expression I found. But would like to remove the bounce effect from the return movement and retain the initial movement bounce.

    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){
    v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
    amp = .05;
    freq = 4.0;
    decay = 2.0;
    value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
    }else{
    value;
    }

    Thank you!

  • Shane Mccleery

    July 31, 2013 at 7:22 pm

    Dan,

    This exp looks and works great.

    I’m just getting into AE and expressions and I was wondering what the proper steps to being able to use this script in reverse, or just be able to use this script going from any two sizes.

    Like say I want to go from 100% to 20% and still retain the intertial bounce how would I edit your script.

    I guess I just am not very good with changing variable and figuring out what they do.

  • Dan Ebberts

    July 31, 2013 at 7:35 pm

    I think I would use the keyframe version of the expression for that (set linear keyframes for 100% and 20% the apply this expression to the scale property) :


    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

    More info here:

    https://www.motionscript.com/articles/bounce-and-overshoot.html#kf-overshoot

    Dan

  • Shane Mccleery

    July 31, 2013 at 8:04 pm

    Dan

    You are a good man!This is exactly what I was looking for. Thanks for all the help you provide to people like me and everyone in general 🙂

  • Scott Green

    December 23, 2014 at 4:32 pm

    I’ve been a big fan of this expression for some time now I’m just wondering if there’s a way that something can be added to it to make it scale back down to 0 after a set amount of time?

    I’ve only been able to achieve this by attaching my objects to a null and then scaling the null down where I want the object to scale out. Any ideas?

    Creative motion graphics, animation, video production and graphic design

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