Max speed/force?

Oct 29, 2009 at 8:41 PM

Hi,

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 5:31 PM
Edited Nov 2, 2009 at 5: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 5:45 AM

I answered this here http://farseerphysics.codeplex.com/Thread/View.aspx?ThreadId=230299 if you're still interested.