This project has moved. For the latest updates, please go here.

Max speed/force?

Oct 29, 2009 at 7:41 PM


To fix some problems with my project I had the idea to add a max velocity and max speed. Does anyone know of a simple change I can make to the physics engine to do this?

Nov 2, 2009 at 4:31 PM
Edited Nov 2, 2009 at 4:32 PM

Terminal velocity is normally controlled with linear drag, but if you need to strictly enforce that a body doesn't move faster than a certain speed, you can do a check on each body on each update.  If the body is moving too quickly, apply an impulse in the opposite direction to slow it down instantly.

For example:

float maxSpeed = 100;
float maxSpeedSq = maxSpeed*maxSpeed;


float vel = body.Velocity.LengthSquared()
if(vel > maxSpeedSq)
    body.ApplyImpulse(body.Velocity.Normalized() * (maxSpeed - Math.Sqrt(vel)))

Of course, I'm never sure of myself, so don't sue me if it doesn't work. =D

Oct 10, 2010 at 4:45 AM

I answered this here if you're still interested.