I think I've configured Box2d to have some sort of maximum velocity for any body, but I'm not sure. I apply an impulse like (100000000, 100000000)
, and the body moves just as fast as (100, 100)
- which is not that fast at all.
I'm using the Box2d XNA C# port.
My game is a top-down 2d.
Here is some code that may be relevant:
private readonly Vector2 GRAVITY = new Vector2(0, 0);
public void initializePhysics(ContactReporter contactReporter)
{
world = new World(GRAVITY, true);
IContactListener contactListener = contactReporter;
world.ContactListener = contactListener;
}
public void Update(GameTime gameTime)
{
// ...
worldState.PhysicsWorld.Step((float)gameTime.ElapsedGameTime.TotalSeconds, 10, 10);
//...
}
Here is some example code that applies the impulse:
private void ApplyImpulseFromInput()
{
Vector2 movementImpulse = new Vector2();
if (inputReader.ControlActivation(ActionInputType.MOVE_LEFT) == 1f)
{
movementImpulse.X = -Constants.PLAYER_IMPULSE_CONSTANT;
} else if (inputReader.ControlActivation(ActionInputType.MOVE_RIGHT) == 1f)
{
movementImpulse.X = Constants.PLAYER_IMPULSE_CONSTANT; ;
}
if (inputReader.ControlActivation(ActionInputType.MOVE_UP) == 1f)
{
movementImpulse.Y = -Constants.PLAYER_IMPULSE_CONSTANT; ;
} else if (inputReader.ControlActivation(ActionInputType.MOVE_DOWN) == 1f)
{
movementImpulse.Y = Constants.PLAYER_IMPULSE_CONSTANT; ;
}
model.Body.ApplyImpulse(movementImpulse, model.Position);
}
If Constants.PLAYER_IMPULSE_CONSTANT
is anywhere from 1000f
to 1000000000f
, the player can move at most (-120, -120)
to (120, 120)
. If the constant is less, like 1f
, the player will move more slowly.
This code is used to set up physics for everything in the game world:
controller.Model.BodyDef = new BodyDef();
controller.Model.BodyDef.type = controller.Model.Mobile ? BodyType.Dynamic : BodyType.Static;
controller.Model.Body = worldState.PhysicsWorld.CreateBody(controller.Model.BodyDef);
controller.Model.Body.SetLinearDamping(10.0f);
Could it possibly be the linear damping? I changed it from 10.0f
to 0
, with no effect.
UPDATE: Weirdness with linear damping: I have made these observations on the body that is moved with the apply impulse method above:
Linear Damping Max Speed
0f 120
10f 120
50f 120
55f 90
60f 0
70f 0
100f 0
100000f 0
Why is there a range of sensitivity in linear damping between 50f
and 60f
?