I'm writing my sBox2D game character's movement code, but my implementation of jumping is failing:
When I press the Jump key, the character jumps OK. However, when I press jump and another key (like the left arrow key) at the same time, it kind of blocks the jump from happening.
I'm using applyForceToCenter
and setLinearVelocity
to move the character.
What could the problem be?
Here's how I've bound keys trigger movement:
// press W key (aka Up key or BTNup)
if (RHInput.isDown(RHInput.BTNup)) {
if(rhcl.isPlayerOnGround()) {
toniBody.applyForceToCenter(0, 100, true );
System.out.println("Toni jumps");
}
}
// press A key (aka Left key or BTNleft)
if (RHInput.isDown(RHInput.BTNleft)) {
if(rhcl.isPlayerOnGround()) {
toniBody.setLinearVelocity(-5, 0);
System.out.println("Toni walks left");
}
else {
toniBody.setLinearVelocity(-1, 0);
}
}