Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions bouncing ball expression

  • Trent Armstrong

    January 7, 2011 at 2:55 pm

    Ahh. The old browser auto-crop of expressions trick. They get me with that all the time!

    I loaded it in Firefox and it works. Thanks for the heads-up on browser issues.

    Trent

    Trent Armstrong – Creative Cow Leader
    https://www.dallasaeug.com

  • David Cabestany

    May 21, 2013 at 5:19 pm

    I’m getting the same timeout error and I’m adding the expression to a null, the thing is I can’t replace it with a solid, because it’s an Element 3D Group Null, so it’s being referenced by the 3d objects, any suggestions on how to fix this error?

  • David Cabestany

    May 21, 2013 at 5:36 pm

    Update: I’m using this expression instead, it works perfectly, no timeout errors or anything like. Just change where it says LAYER NAME HERE to the floor layer you want to use.
    Thanks to Marcus Geduld and his excellent book After Effects Expressions for it.

    var bouncesPerSecond=1.5;
    var bounceStrength=200;
    var decayRate=.5;
    var floor=thisComp.layer("LAYER NAME HERE").transform.position[1]
    var bounceOffset= Math.abs(Math.cos(bouncesPerSecond*time*2*Math.PI));
    var y=bounceStrength*bounceOffset/Math.exp(decayRate*time);
    floor=floor-(height/2);
    [position[0], floor]-[0,y]

  • Peter Menich

    July 24, 2014 at 9:57 am

    Hey Dan,

    Is there anyway to define a ‘start time’ for this expression?

    Elements start to drop on frame 0, I tried dragging/staggering the footage in the timeline but they all still start dropping on the first frame.

    I need them to start dropping on their ‘inPoint’ or after a defined amount of time, if thats possible.

    Cheers

    Pete

  • Dan Ebberts

    July 25, 2014 at 8:55 pm

    You just need to replace all references to time with a variable that represents the time elapsed since the bounce start time. Like this for the position expression:

    tStart = inPoint; // or whatever time you want
    tt = Math.max(time-tStart,0); // I used tt because t is already used

    Vy0 = 500; //initial y velocity (pixels/second)
    Vx0 = 300; // initial x velocity (pixels/second)
    g = 2500; // gravity (pixels/second/second)
    floor = 400;
    e = .85; //elasticity

    b = floor – position[1];
    h = b + Vy0*Vy0/(2*g);
    T = Vy0/g + Math.sqrt(2*h/g);

    if (tt < T){
    y = Vy0*tt – g*tt*tt/2 + b;
    }else{
    Vy = -(Vy0 – g*T);
    while (true){
    Vy *= e;
    t = T;
    T += 2*Vy/g;
    if (tt < T){
    t = tt – t;
    y = Vy*t – g*t*t/2;
    break;
    }else if (T – t < thisComp.frameDuration){
    y = 0;
    break;
    }
    }
    }
    [position[0] + Vx0*tt, floor – y]

    Dan

Page 2 of 2

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