Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Error with gravity expression

  • Error with gravity expression

    Posted by David Rodriguez on May 11, 2008 at 6:59 am

    I am using CS3 and have applied an expression for bounce to a graphic. I have received the following error

    After Effect warning: Timeout while waiting for the engine.
    Expression disabled

    Error occured at line 16.
    Comp: RxTV
    Layer: 1 (YELLOW_DOT.psd)
    Property: Position

    The Expression I applied is as follows

    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 (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*time, floor - y] Any help fixing my problem or passing me a gravity with floor expression that works with CS3 would be much appreciated. Thank You

    David Rodriguez replied 18 years ago 3 Members · 11 Replies
  • 11 Replies
  • Dan Ebberts

    May 11, 2008 at 6:23 pm

    My guess is that you’ve got your graphic positioned below the “floor” which you’ve got set to 400. If so, try moving the graphic to a location where y is less than 400.

    Dan

  • David Rodriguez

    May 11, 2008 at 6:39 pm

    You were correct Sir! I changed my floor to 1050 and the error has gone away. Now I need to figure out (have someone tell me) why the balls all bounce to the right and off screen.

    My animation is this. I have a gel capsule graphic that breaks open to drop sixty tiny capsules onto the floor, they then bounce up and down a few times then form a heart wave graphic.
    I am trying to get the bounce to look natural. The tiny capsules are all released from a central point in the screen and I need them to bounce and spread out over the width of the screen. Currently they all bounce to the right and off screen.
    Perhaps I need a different expression or some randomness?

    Any help is much appreciated!
    David

  • Dan Ebberts

    May 11, 2008 at 11:08 pm

    You control the horizontal direction and speed with the Vx0 variable. If you make that negative, it will move to the left. If you make it smaller, it will move slower. To get it to stop though, I think you’d have to add some friction so that it slows down on each bounce. Probably not too tough. I don’t have time to work it out right now, but I’ll take a look at it when I get some time (unless somebody else wants to jump in).

    Dan

  • David Rodriguez

    May 11, 2008 at 11:42 pm

    After playing with the settings for a few hours I understand the expression much better. If I could just get the line

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

    to randomly choose a number between -200 and 200 I would be well on my way to making this work exactly how I want it to.

    Any help is much appreciated
    David

  • Darby Edelen

    May 11, 2008 at 11:52 pm

    [David Rodriguez] “to randomly choose a number between -200 and 200 I would be well on my way to making this work exactly how I want it to. “

    Do you want it to choose a random value on every frame or one random value for the duration of the composition? For the first case use:

    random(-200,200);

    For the second use:

    seedRandom(index, true);
    random(-200,200);

    The second one picks a random value and doesn’t update it over time.

    Darby Edelen
    Lead Designer
    Left Coast Digital
    Santa Cruz, CA

  • Darby Edelen

    May 12, 2008 at 12:10 am

    Also, I thought I’d take this space to mention that I wrote a little expression that will take keyframed values and add an exponential decay to the end of the keyframes… This is a derivative of something Dan did on his site, so credit is due, as usual, mostly to Dan =)


    n = value.length;
    if(numKeys > 1){
    firstKey = key(1).time;
    lastKey = key(numKeys).time;
    v = velocityAtTime(lastKey - thisComp.frameDuration);
    a = 20;
    decay = 2;
    f = 1/a;
    t = Math.max(time - lastKey, 0);
    x = a * Math.sin(v[0] * t * f) / Math.exp(decay * t);
    y = a * Math.sin(v[1] * t * f) / Math.exp(decay * t);
    z = a * Math.sin(v[2] * t * f) / Math.exp(decay * t);

    value + [x,y,z];
    }
    else value;

    This doesn’t work for something bouncing off a hard surface like a floor, but it works well to simulate springy motions. In the above you may want your own values for ‘a’ and ‘decay.’ The above is for a 3 dimensional vector (such as 3D position or 3D scale). For a scalar value (1 dimensional like rotation) you would use:


    if(numKeys > 1){
    firstKey = key(1).time;
    lastKey = key(numKeys).time;
    v = velocityAtTime(lastKey - thisComp.frameDuration);
    a = 2;
    decay = 2;
    f = 1/a;
    t = Math.max(time - lastKey, 0);
    x = a * Math.sin(v * t * f) / Math.exp(decay * t);

    value + x;
    }
    else value;

    Darby Edelen
    Lead Designer
    Left Coast Digital
    Santa Cruz, CA

  • David Rodriguez

    May 12, 2008 at 2:15 am

    Thanks for all of the help gentlemen!
    I’m having a hard time replacing

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

    with

    seedRandom(index, true);
    random(-200,200);

    How should the finished line look?

    David

  • David Rodriguez

    May 12, 2008 at 2:34 am

    I think this is it. Check out the big brain on Dave.

    seedRandom(index,true);
    Vx0 =random(-200,200); // initial x velocity (pixels/second)

  • David Rodriguez

    May 12, 2008 at 2:55 am

    Now how do I turn it off? Is there an easy way to let me take control of the animation at a certain point then have the expression take over further down the line?

    Thank You for time and attention
    David

  • Darby Edelen

    May 12, 2008 at 2:57 am

    That’s not built in to this version of the expression =( I’ll keep working on it though, it’s something I expect to use a lot, I really like the results I’m getting for my current project =)

    Darby Edelen
    Lead Designer
    Left Coast Digital
    Santa Cruz, CA

Page 1 of 2

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