I'm making a game using LibGDX, and with LibGDX, the Box2D wrapper that comes with it. Specifically, my game is a 2D sidescroller.
My problem is with my player sprite. I need very precise movement for the player, so I decided I would set it up so when the player presses an arrow key, it would call playerBody.setLinearVelocity()
, and then when they stopped pressing the keys, it would reset their linear velocity to 0.
In my game, I have gravity. To make sure the player falls while moving left and right, I created the method run()
:
public void run(float x) {
playerBody.setLinearVelocity(x, playerBody.getLinearVelocity().y);
}
This works fine when my player is freefalling. However, when my player moves against any static body (including vertical walls), they stop falling for as long as I'm holding down the arrow key that sticks them to the wall.
Does anyone know why this might be? Thanks in advance.
Also, here's my friction, density, and restitution for the playerBody:
friction = 0.1f
restitution = 0.01f
density = 0.4f