Creative Communities of the World Forums

The peer to peer support community for media production professionals.

  • Posted by Jeff Mcbride on March 22, 2006 at 7:41 am

    Is there any way to easily simulate gravity? I am working on a basketball animation and was wondering if there’s a simpler way than keyframing it out. Is there something I can apply to it? or a pixels/sec ratio that works well with gravity? Thanks!

    Mike Clasby replied 20 years, 2 months ago 3 Members · 3 Replies
  • 3 Replies
  • Mylenium

    March 22, 2006 at 8:20 am

    You could apply an expression to the position:

    X=position[0];
    Y=position[1]+ 9.81*Math.pow(time,2);

    [X,Y]

    This will allow you to combine keyframing with procedural gravity. You will need to tweak the gravity value – AE calculates in pixels, not meters, so 9.81 will either be too little or too much for your situation.

    Mylenium

    [Pour Myl

  • Mike Clasby

    March 22, 2006 at 8:31 am

    There is a script call Gravity.jsx

    Select the layer you want to apply gravity to,

    File > Run Script > Choose File > and you should open up to the folder (demos)

    Note: (demos) is a folder nested here (on a PC): C drive > Program Files > Adobe > After Effects 6.5 > Support Files > Scripts > Demos

    there should be a file there named “Gravity.jsx”

    select it.
    Now when you click the “Run Simulation” in the Gravity script palette you’ll get keyframes of the chosen gravity attributes (chosen in the palette). Also a cool plus, if you keyframe position as in moving the ball (or whatever layer is selected when you open the script) you’ll get a nice moving ball bouncing, note two that the layer bounce around a box created in the palette, just click he “?” for details>

  • Mike Clasby

    March 22, 2006 at 8:53 am

    Here a set of expressions,very nice with squish a squash as the ball bounces, not as hairy as it looks if you can copy/paste expressions (Alt + Click the Stopwatch for the property you want to apply the expression to, then paste)

    I just remembered Dan had a nice bouncing animation expression from this post:

    Name: Dan Ebberts
    Date: Sep 14, 2004 at 11:40:45 am
    Subject: Re: bouncing animation

    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 poisition:

    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

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