• Advertisement

Archived

This topic is now archived and is closed to further replies.

Gravity is right getting on my arse no?

This topic is 5995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I want to use gravity in me game, but methinks I don't know to to do it. So far, me particles have x, y & z positions, and x, y & z speeds, where the z axis is the height, and the x & y are the other two (I don't know their names...) Say that one ot these particles is in the air, what is the values that me needs to adds to each axis velocity? I don't know, you see. Forgive me English, please. Edited by - BoyWithNoBanana on September 24, 2001 2:59:35 PM

Share this post


Link to post
Share on other sites
Advertisement
if you want gravity, you need to add the gravity_accseleration!
on earth, this is 9.81 (presise enough);
add this to the z_speed!
if the object falls straight up, you need to switch the sign!
the 9.81 is per second, so if you got 54 frames per second, you add 9.81/54

g = 9.81

z_speed += (g/fps);

the world gravity is prety strong, in most games and action movies, the g (9.81) is often redused.

on mars, g = (9.81/3)
on the moon g = (9.81/6) i think

-Anders-Oredsson-Norway-

Share this post


Link to post
Share on other sites
uncutno forgot to mention that 9.81 is in the units of meters per second squared. Its only the correct number if your model is in meters and you''re measuring time in seconds. If you''re using feet for length then the acceleration would be 32 feet per second squared. (But I suspect you''re not using feet!)

But as uncutno says, you can freely adjust that number to get the look and feel that you need!

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
Well it can get more complex once you add in *other* forces (e.g., collisions, and perhaps things like springs or aerodynamic drag). Don''t even think about this now, since you''re just at the beginning, but uncutno''s solution is actually a technique called Euler integration, which can easily and rapidly break down when the problem is complicated by other forces. But it is a good way to get a basic system up and running.

The next step that many folks take is to upgrade to Runge Kutta integration. Its trickier, but there''s many references out there, even in the games community.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
Thanks man. It took no time whatsoever to get me thing going right, and now it looks great! I''m having great fun.

At the moment, I don''t really care about any other effects, except for one...
Wind.

Assuming I had x, y, and z speeds for the wind, how do I put them into the particles? I''ve tried adding them on to the particles speed axis, but the moment I add any wind, they fly off! I''m probably missin the obvious...again, but that''s me for ya.

Share this post


Link to post
Share on other sites
the proble with wind, is that the force on you object is relative, to the speed dif of the object and the wind! Its imposible to make a objekt go faster then the wind, only by the power of the wind!

therfor, we need a dif vector!

dif_x = wind_speed_x - obj_speed_x;
dif_y = wind_speed_y - obj_speed_y;
dif_z = wind_speed_z - obj_speed_z;

then you need a factor... you need to find this yourselfe, but
0.05 should do it :-)

obj_speed_x += (dif_x * 0.05);
obj_speed_y += (dif_y * 0.05);
obj_speed_z += (dif_z * 0.05);

this way, if the objekt moves faster then the wind, it will slow down!

As ghrodes_at_work said, this is a simplification of a much more complex thing! the 0.05 factor may be calculated for real by the shape of the object, and the mass, but this is not necesary for a "simple" game :-) If your going to add more then this, you need to convert both wind and gravity to real forces:
Force = mass * accseleration, and then base ewerything on a much more general and fleksible force simulator :-)







-Anders-Oredsson-Norway-

Share this post


Link to post
Share on other sites
Here''s a quick-and-dirty way to calculate a wind force. Actually, this is pure aerodynamic drag, and the equation is the same one used by airplane designers for their preliminary designs. Most objects have some kind of lift as well, but that''s trickier to deal with:

Drag_magnitude = 0.5 * rho * V * V * Sref * CD

Here, rho is the air density (1.225 kg/cubic_meter or 0.00237 slugs/cubic_foot at sea level)

V is the air speed relative to the object (the "0.5 * rho * V * V" part of the equation is called "dynamic pressure").

Sref is a reference area. If your object is more like a sphere than an airplane, use the cross section area of a representative sphere----don''t use the bounding sphere as its too big. If your object is more like an airplane, use the area of the projection of the object onto the ground----or a quick and dirty estimate. If you have particles, then the cross section area of a small sphere is ideal.

CD is drag coefficient. For a sphere-like particle, use 1.0. This is just a guess. The real value depends on so many things, and all you''re really looking for is something that looks good anyway.

So, Drag_magnitude is just the value of the force. The *direction* of the force is given by the x, y, z components of V. So, really, if your relative velocity is V_vector then the drag force is:

V = length(V_vector),

Drag_force = 0.5 * rho * length(V_vector) * Sref * CD * V_vector

Notice how one of the "V"''s in "V * V" is now embedded in the V_vector at the end? Saves from having to normalize/unitize V_vector.

The thing to keep in mind is that V_vector must be the wind velocity *relative* to the particle. If the particle is still, then V_vector is just the wind velocity. If the particle is moving at Particle_velocity then the V_vector is:

V_vector = Wind_velocity - Particle_velocity

So if the wind is 10mph to the right and the particle is moving 10mph to the right, then there is no relative wind and the drag is zero. If the object is moving 10mph to the left then the relative wind is 20mph to the right.

Does that help? It complicates your integration, assuming you implemented uncutno''s approach exactly as he stated it. For example, whereas for pure gravitational acceleration you can ignore the mass of the particles (because it drops out of the equation of motion), when you add wind, mass must be included!

The equation of motion (Newton''s second law of motion) is:

Force = mass * acceleration

Force and acceleration are vectors. Mass is a constant, and you can adjust it to look good. Units of mass are slugs or kilograms. Force is pounds or Newtons. Acceleration is feet/square_second or meters/square_second. Make sure your numbers and units are consistent.

Force is now equal to the drag force + weight of the particle (mass * g, with g being the number uncutno gave).

Force = Drag_force + mass * g

The "mass * g" vector acts in the negative z direction.

Then solve for acceleration:

acceleration = (Drag_force + mass * g)/mass

(You can see that if Drag_force = 0 then acceleration = mass*g/mass = g, so mass drops out as in uncutno''s method.)

And use (for now) Euler integration for each frame:

velocity += acceleration * dt

where dt is the time change between frames. Lots of contraversy about how to choose dt, but quick and dirty is:

dt = 1/fps (ex. if 60 fps, use dt = 1/60).

Hope this isn''t too confusing. The wind should add to your fun quite a bit!

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
As uncutno said, with respect to wind calculations, simplifications that are very fast and look good are perfectly acceptable for games.

You'll find that my discussion of wind drag actually *calculates* the "factor" rather than just assuming 0.05 for example.

uncutno's equation doesn't look like mine. You'll see that his drag really looks like:

drag_force = coefficient * V

whereas mine looks like:

drag_force = coefficient * V * V

What's the difference? For very very small V, not much, since there isn't much difference between V and V*V. As long as V <= 1 or so, uncutno's solution and mine will give drag_force values of similar magnitude (assuming the coefficients are the same).

uncutno's drag solution is faster to calculate and may look perfect for slow particles and low wind.

My solution is slower to calculate, but is realistic for faster-moving particles and higher wind speed.

You choose what you want!

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.


Edited by - grhodes_at_work on September 25, 2001 11:41:45 AM

Edited by - grhodes_at_work on September 25, 2001 11:42:32 AM

Share this post


Link to post
Share on other sites
Thank you both SO much! This is excactly what I wanted! At the moment, me particles are falling nicesly with the gravity in there, and this should make it even better. It was a little complicated, but I''m following. I don''t need any other affects at the moment, so I''ll just try these out together and see what happens...

Share this post


Link to post
Share on other sites

  • Advertisement