Sign in to follow this  

Which formula would you use for "velocity loss"

This topic is 4686 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

In my 2D engine, I have a relatively robust particle system which is controlled by objects called Emitters. These emitters have various properties. Anyway, I'm looking to add in a variable which I've called velocityLoss, for lack of a better name. This will simulate drag, slowing down particles. My first idea was to tie it linearly to velocity and do the following calculation every frame: velocity -= velocity * velocityLoss * timeStep; The idea would be that if velocityLoss is 1, then the deceleration for that frame would stop the particle in one second, if it wasn't changed every frame to account for the slower velocity, of course. Velocity is in units/sec and timeStep is in seconds. However, this is obviously not the case, as a graph would have a negative but increasing slope, and actually never quite reach 0. The inaccuracy of this linear estimation isn't really a concern. I suppose this might be a good model for drag, but is it . . how should I put it. . . straight forward enough? That is, are there more common formulas or values which are used for this type of thing? Or is "inventing" a new method acceptable. Usually these values will be set in a graphical program, so the user will be able to see what the value does in real-time. Keep in mind that there are times where there could be hundreds or thousands of particles, so keeping the formula simple is better. Any thoughts? --Vic--

Share this post


Link to post
Share on other sites
drag force can be approximated with

Force = -Vel * k;

so then when you integrate

V += Force/mass * dt

so in essence, it's the same as

velocity -= velocity * velocityLoss * timeStep;

call it drag instead of "velocity loss" BTW, that should clear things up.

you can also add a squared magnitude of the velocity, something like

velocity -= velocity * (drag * timeStep) + velocity.Direction() * (velocity * velocity * drag2 * timestep);

ect...

a first order drag should be sufficient for a particle system. You want speed over accuracy, and that would create a realistic drag force on the particle (think explosions). Doing anything more complicated would probably be overkill.

Yes it would never reach zero and the particles will drift slowly, but is it that much of a problem for particle system...

you can also clamp the velocity components if their magnitude is below a given amount, for a quick hack example...

Particle.V += Particle.V * Particle.Drag * dt;

if (Particle.V.MagnitudeSquared() < fStaticFrictionSquared && Particle.IsOnFloor())
{
V = Vector(0, 0, 0);
}

Share this post


Link to post
Share on other sites
Great, drag it is, and the linear approximation it is too :) I'm not super concerned about accuracy for this, as you said. I just wanted to make sure I wasn't overlooking some obvious method that's used.

Thanks for the help,

--Vic--

Share this post


Link to post
Share on other sites
Bear in mind that velocity *= damping_factor;, where damping_factor is just under one, is equivalent to velocity -= velocity*drag, where drag = 1-damping_factor (i.e., where drag is just above zero). I suppose with a variable timestep, velocity *= damping_factor*timestep; should be a sufficient approximation too, but really, with explicit numerical integration, variable timestep is just Evil(tm).

Share this post


Link to post
Share on other sites
Quote:
Original post by Roof Top Pew Wee
But I have a variable timestep (who wants to limit frame rate, yuck).

--Vic--

almost everybody wants that, though im not sure i agree with them.

Share this post


Link to post
Share on other sites

This topic is 4686 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this