Advertisement

How do I get particles to fall?

Started by January 29, 2002 08:39 PM
3 comments, last by executor_2k2 23 years ago
I''m trying to get a gravity effect with my particle system, but I''m just not sure how to go about it. Do I use a parabolic equation? Do i just set a gravity variable that increases over time and subtract that from the particles height? I would like to use the fastest method possible.
Well, that was a waste of 2 minutes of my life. Now I have to code faster to get 'em back...
increase the velocity in the direction of the gravitys pull.
Advertisement
Track the velocity of the particle. Each frame, add a (constant) appropriate downward vector to the velocity (ie. appropriate to the scales you are using). The downward velocity will thus increase over time and the particle will behave nicely.

Done properly, things like parabolic trajectory will happen automatically and you don''t need to compute them as such.
There are 3 vector quantities you have to consider for each particle. Position, Velocity and Acceleration.

If there are no other forces but gravity acting on the particle then acceleration will be

Vector a(0.0f, -9.8f, 0.0f);

When you initialize your particle engine you need to position the particle

Vector p(10.0f, 20.0f, 30.0f);

and give it a velocity

Vector v(10.0f, 20.0f, 0.0f);

here are some simple functions that model constant acceleration:

s = ut + 1/2a(t^2)
v = u + at
v^2 = u^2 + 2as

where

s = displacement
u = initial velocity
v = final velocity
t = time
a = acceleration

After some time has passed. ie you''ve moved on to the next frame you can calc a new position and speed.

using s = ut + 1/2a(t^2)

(vector)newPos = (vector)p * (scalar)t + 1/2 * (vector)a * (scalar)t * (scalar)t;

and using v = u + at

(vector)newVel = (vector)v + (vector)a * (scalar)t;


So now you''ve calculated a new position and a new velocity.

p = newPos;
v = newVel;


keep doing that over time and your particles will fly around realistically.
If you limit the number of times this action happens per second, say it happens once per frame, 30 frames per second, then your downward velocity would be += (9.8/30).
You can be sure then that every frame, you particle moves downward at the fraction of the required.

Good eh

Unifex
Unifex

This topic is closed to new replies.

Advertisement