How do I get particles to fall?
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...
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.
Done properly, things like parabolic trajectory will happen automatically and you don''t need to compute them as such.
February 01, 2002 10:31 AM
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 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
You can be sure then that every frame, you particle moves downward at the fraction of the required.
Good eh
![](smile.gif)
Unifex
Unifex
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement