I have a very simple LibGDX game that uses Box2d. Right now, it is just a ship that moves around on a map. I can make the ship move with keyboard controls if I use the body.setTransform()
method to change the ship's location, but that obviously does not take advantage of the capabilities of Box2d. I want to control the player ship using the applyForce()
method, but that method for some reason does not do anything, no matter how high or low I set the force. I also tried applyLinearImpulse()
and setLinearVelocity()
, and both had the same effect: nothing. And I confirmed through logging that my ship's velocity was in fact remaining at a constant 0.0 and not just changing by miniscule amounts.
Here's the relevant stuff from the game loop and entities:
The part in question particularly:
public void update(){
this.applyIntendedMovement();
}
public void applyIntendedMovement(){
if(this.isMovingUp){
this.body.applyForceToCenter(new Vector2(0,100).scl(this.SPEED_FACTOR), true);
}
}
Why does the call to applyForce()
do nothing? Also, I explicitly set a density when creating my Player body, but when I check the player's mass at any given moment, it is 0.0. I know there is a good chance these two problems are related, but I have no idea what to do.