Speed issues when using ApplyForce (beginner question)

Topics: User Forum
Apr 7, 2010 at 12:51 AM
Edited Apr 7, 2010 at 12:52 AM

I've just started fiddling around with the engine and i'm running into a couple of issues trying to control my characters speed.


1st, my character is controlled by the thumbstick, and I'm simply finding the velocity in relation to the stick direction, and doing .ApplyForce(player.velocity). Works beautifully of course, but my problem is in limiting the speed my player reaches. I tried to figure it out but kept getting odd results. I'm just looking to find the easiest way to limit my characters motion to a set speed when using ApplyForce.


2nd, I want my character to quickly slow to zero when the thumb stick is at rest, I tried just applying -velocity, but that was met with wacky results, obviously. Whats the best way to go about this?


Help would be amazing, thanks!

Apr 7, 2010 at 1:04 AM

The way I solved this was to balance the force applied and the linear drag.  I can't remember exactly but I think the force was around 14 and the drag around 10.  Just plug and chug until you get the results you want.  The LinearDrag will give your body a maximum speed (like terminal velocity) and will cause your body to slow to a stop.

Apr 7, 2010 at 12:58 PM

Just tried applying a LinearDragCoefficient to the Body and it worked.

Here is another way I slow my player down to a stop without having him jerk to a stop.

float velX = playerBody.LinearVelocity.X;
if (velX > 0)
playerBody.LinearVelocity.X /= 2f;
Apr 7, 2010 at 6:44 PM

Thanks guys! i'm going with the lineardragcoefficient way. works really well.


thanks again.