Creative COW SIGN IN & SETTINGS :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: ForumAE BasicsAE ExpressionsTutorialsArticlesPodcastsMotion GraphicsTrainingCinema 4D

Error with gravity expression

Cow Forums : Adobe After Effects Expressions
Error with gravity expression
by David Rodriguez on May 11, 2008 at 6:59:43 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

Respond to this post     Return to posts index

Re: Error with gravity expression
by Dan Ebberts on May 11, 2008 at 6:23:34 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



Respond to this post     Return to posts index

Re: Error with gravity expression
by David Rodriguez on May 11, 2008 at 6:39:00 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

Respond to this post     Return to posts index


Re: Error with gravity expression
by Dan Ebberts on May 11, 2008 at 11:08:41 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



Respond to this post     Return to posts index

Re: Error with gravity expression
by David Rodriguez on May 11, 2008 at 11:42:01 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

Respond to this post     Return to posts index

Re: Error with gravity expression
by Darby Edelen on May 11, 2008 at 11:52:35 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

Respond to this post     Return to posts index


Re: Error with gravity expression
by David Rodriguez on May 12, 2008 at 2:15:09 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

Respond to this post     Return to posts index

Re: Error with gravity expression
by David Rodriguez on May 12, 2008 at 2:34:00 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)

Respond to this post     Return to posts index

Re: Error with gravity expression
by Darby Edelen on May 12, 2008 at 12:10:54 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

Respond to this post     Return to posts index


Re: Error with gravity expression
by David Rodriguez on May 12, 2008 at 2:55:52 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

Respond to this post     Return to posts index

Re: Error with gravity expression
by Darby Edelen on May 12, 2008 at 2:57:16 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

Respond to this post     Return to posts index

Re: Error with gravity expression
by David Rodriguez on May 12, 2008 at 4:07:12 am

Is there an easy way to let me turn this off, control the position and then have the expression come back on?

So here is my final expression,

Vy0 = 200; //initial y velocity (pixels/second)
seedRandom(index,true);
Vx0 =random(-200,200); // initial x velocity (pixels/second)
g = 2500; // gravity (pixels/second/second)
floor = 1050;
e = .82; //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]

Respond to this post     Return to posts index

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   NEXT THREAD >>


FORUMSLIBRARYPODCASTSBLOGSMAGAZINESERVICESNEWSLETTERSNEWSSTOREEVENTS

© CreativeCOW.net All rights are reserved.

[Top]