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

Maximum velocity

Topics: User Forum
Aug 6, 2013 at 12:24 PM
Edited Aug 6, 2013 at 12:28 PM
I am moving an object arround by constantly applying some forces. This is fine, although there are cases when the object receives too much force and goes way too fast.

What would be the recommended way to cap the maximum velocity for an object?
Is recalculating the LinearVelocity on every update sufficient or will that cause issues?

Aug 6, 2013 at 2:24 PM
You might consider applying impulses instead of forces, you might find the behavior more suited to what you're trying to do (depending on what that is).

There shouldn't be a problem with recalculating LinearVelocity every update. The only "issue" I can think of is directly changing the velocity won't have any effect on the rotation, so it's possible that the rotation might look out of place with the velocity (i.e. something spinning fast but moving slow).

Aug 7, 2013 at 2:15 PM
Thanks for the reply Mike.

Impulses seem to work better for my situation indeed, however, I still have a challenge with reacting to other forces so might need to combine both.
Aug 7, 2013 at 7:11 PM
Forces are already limited as the linear and angular velocities are capped. You can see their value in Settings.cs (MaxTranslation and MaxRotation)
Jan 21, 2015 at 1:25 AM
Aply forces only when the object is moving under the speed you want.
Set the body.LinearDamping ( default is 0f, try 1f or 2f ) to a higher number to reduce the effect of the forces.
Make something like this:
        _wheel1.LinearDamping = 1f;

        if (keyboardManager.IsKeyDown(Keys.D))
            if (-_wheel1.AngularVelocity <= speed)