Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Bouncing movement

  • Posted by Esteban Duperly on May 4, 2007 at 11:59 pm

    Hi! I’ve been trying to create a bouncing movement in AE. I tryed with a script I found in a folder named “bouncingBallSimulation”, run it from inside of AE but didn’t work. I need to animate a seed that falls from the sky and bounces a couple of times.

    Does any one know how to create it?

    thanks a lot!

    Xavier Gomez replied 14 years, 6 months ago 7 Members · 14 Replies
  • 14 Replies
  • Mike Clasby

    May 5, 2007 at 2:24 am

    Hetre are a couple of bouncing expression from an old post by Dan Ebberts. The second one for scale does a little squish-squash that you might not need for a seed, it’s up to you.

    Bouncing animation expression

    Here are a couple of bounce simulation expressions. The first one is for position and the second is for scale. With the parameters set the way they are, your object will drop until it reaches y = 400 (“floor”) and then bounce. You can control everything with the parameters (even better- assign them to sliders). You can use Vx0 and Vy0 to give your object an initial velocity – turning it into a projectile. For best results, move the anchor point of your object to the bottom. Here’s the expression for position:

    Vy0 = 500; //initial y velocity (pixels/second)

    Vx0 = 100; // initial x velocity (pixels/second)

    g = 2500; // gravity (pixels/second/second)

    floor = 400;

    e = .85; //elasticity

    d = .03; //squash factor

    spd= 10; //speed of squash oscillation

    decay= 10.0; //how fast squash slows down

    b = floor – position.valueAtTime(0)[1];

    h = b + Vy0*Vy0/(2*g);

    T = Vy0/g + Math.sqrt(2*h/g);

    if (time < T){ x = scale[0]; y = scale[1]; }else{ Vy = -(Vy0 - g*T); while (true){ max_dev = e*Vy*d; Vy *= e; t = T; T += 2*Vy/g; if (time < T){ t = time - t; x=scale[0]+max_dev*Math.cos(spd*(t))/Math.exp(decay*t); y=scale[0]*scale[1]/x; break; }else if (T - t < thisComp.frameDuration){ x = scale[0]; y = scale[1]; break; } } } [x,y] And for scale: Vy0 = 0; //initial y velocity (pixels/second) Vx0 = 0; // initial x velocity (pixels/second) g = 2500; // gravity (pixels/second/second) floor = 400; e = .85; //elasticity d = .02; //squash factor spd= 10; //speed of squash oscillation decay= 10.0; //how fast squash slows down b = floor - position.valueAtTime(0)[1]; h = b + Vy0*Vy0/(2*g); T = Vy0/g + Math.sqrt(2*h/g); if (time < T){ x = scale[0]; y = scale[1]; }else{ Vy = -(Vy0 - g*T); while (true){ max_dev = e*Vy*d; Vy *= e; t = T; T += 2*Vy/g; if (time < T){ t = time - t; x=scale[0]+max_dev*Math.cos(spd*(t))/Math.exp(decay*t); y=scale[0]*scale[1]/x; break; }else if (T - t < thisComp.frameDuration){ x = scale[0]; y = scale[1]; break; } } } [x,y] Dan

  • Lord Scales

    May 5, 2007 at 1:49 pm

    Sometimes Dan almost kill us.
    But he is incredible!

    Lord Scales

  • Esteban Duperly

    May 5, 2007 at 2:48 pm

    Hi Yikesmikes, thanks for answering. I may be doing something wrong for I copyed and pasted the two expression into AE and didn’t work. What happens now is that my object is now placed near the left top of my composition (720×480) and barely moves a few pixels. It does try to make a kind of “bounccing movement”, but it doesn’t drop until it reaches the floor neither it behaves like an object that hits the floor and bounces. I’m new with all these expressions stuff, so I am possibly doing something wrong. Can you or anyone help me with that?

    Many thanks!

  • Mike Clasby

    May 5, 2007 at 6:30 pm

    YIKES! did I mess-up. That’s what I get for not testing. Due to a mistake in my work document, both expressions were for Scale, so you’re just getting the Scale Squish and Squash part trying to control the Positional bounce.

    So here are the correct expressions. You’d be better tying the changing factors, like initial velocity, floor, elasticity, etc to sliders, that way when you changed say floor for Position it would change for the Scale also. Like I said, the floor, elasticity etc. need to be the same for both Position and Scale expressions for them to coordinate.

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

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

    if (time < T){ y = Vy0*time - g*time*time/2 + b; }else{ Vy = -(Vy0 - g*T); while (true){ Vy *= e; t = T; T += 2*Vy/g; if (time < T){ t = time - t; y = Vy*t - g*t*t/2; break; }else if (T - t < thisComp.frameDuration){ y = 0; break; } } } [position[0] + Vx0*(-Math.pow(2,-time) +1), floor - y] And for Scale: Vy0 = 500; //initial y velocity (pixels/second) Vx0 = 300; // initial x velocity (pixels/second) g = 2500; // gravity (pixels/second/second) floor = 350; e = .75; //elasticity d = .03; //squash factor spd= 10; //speed of squash oscillation decay= 10.0; //how fast squash slows down b = floor - position.valueAtTime(0)[1]; h = b + Vy0*Vy0/(2*g); T = Vy0/g + Math.sqrt(2*h/g); if (time < T){ x = scale[0]; y = scale[1]; }else{ Vy = -(Vy0 - g*T); while (true){ max_dev = e*Vy*d; Vy *= e; t = T; T += 2*Vy/g; if (time < T){ t = time - t; x=scale[0]+max_dev*Math.cos(spd*(t))/Math.exp(decay*t); y=scale[0]*scale[1]/x; break; }else if (T - t < thisComp.frameDuration){ x = scale[0]; y = scale[1]; break; } } } [x,y] Quickie on adding sliders: Adding a slider for "floor". Effect>Expression Controls>Slider Control

    Select, then double click the slider and rename it “floor”.

    Select the layer and “EE” reveal the expressions. In the position expression, select (highlight) the “350”, then pickwhip (looks like @, the middle of those 3 little boxes by the red numbers) to the “floor” slider you created. Drag that @ to the Slider. And that line of the expression changes from:

    floor = 350;

    to

    floor = effect(“floor”)(“Slider”);

    If you do the same thing for the Scale expression, pickwhip to the same slider named “floor”, then when you make changes in the slider it will effect both the Position and the Scale expressions and they will be coordinated. Even if you don’t use the Scale expression, sliders are a quick way to change things without having to open up the expression and change them manually.

    If this was confusing Aharon (Click his head on the Main After Effects Page) page and then scroll down) has 3 tuts on Expression Controls. Buy the Cow CD with all his tuts, the top most post (I wanna be his agent so I’m hoping for a 10% commission).

  • Esteban Duperly

    May 6, 2007 at 2:01 pm

    Thanks Yikesmikes! it worked just perfect!!

  • Craig Wall

    June 29, 2007 at 7:16 pm

    Saaaa-weet! Thanks a ton!

    Do you have anymore like this–or can you point me in a direction? I love Penner’s easing equations in Flash and I love the idea of using expressions to spruce up common motion.

  • Peter Menich

    December 29, 2007 at 12:13 am

    Hey

    I’m late in coming in on this, but its just what I need and I can’t get it to work!

    when I paste the values into position and scale it hangs for ages, then I get the following error message…

    after effects warning; timeout while waiting for the engine.
    expression disabled

    error occurred at line 23
    comp ‘sponge_test’
    layer 11 (‘S’)
    property: ‘position’

    (on a side note: I wish they’d make these error messages editable so you can cut and paste!)

    Any ideas why its not happening?

    I’m on ae 7.0.1

    Mac G5 PowerPC 2.5 dual

    Peter Menich
    Zedzero MGD
    United Kingdom
    https://www.zedzero.co.uk
    44 (0)1992 584140
    44 (0)7790 900372

  • Xavier Gomez

    October 12, 2011 at 9:06 am

    Hi!

    i arrived here while searching for loops in AE scripts.
    I searched the forum and could only find this page.
    Can someone explain how the while(true) loop works ?

    In the example given above, what should be true for the loop to go on and how does this loop terminates?
    quite unclear to me. (i understand the maths in this example and what is happening, but i dont understand the grammar…)

    Also, is there a possibility to make a loop with a given number of iterations, like for n=1 to 10, with AE ?

  • Dan Ebberts

    October 12, 2011 at 3:13 pm

    You could use while(true) to loop indefinitely, but somewhere in the loop you would need to use a break statement to get you out of the loop.

    It’s more common to see while() used with a conditional variable like this:

    foundIt = false;
    while (! foundIt){
    (code that eventually sets foundIt = true)
    }

    JavaScript does have a for() loop construct, like this:

    for (n = 1; i <= 10; n++){
    (your loop code)
    }

    Dan

  • Xavier Gomez

    October 12, 2011 at 5:38 pm

    Thank you for the fast answer.
    And I’ll know now (that’s helpful!) that AE scripts are written in JavaScript.

    Side question: does it take much computer ressources to write neverending loop scripts like while(true) or is it safe ?

Page 1 of 2

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