I have a problem: I am programming a tiled map game with Box2D but the proble is, that if I press for example D to go forward with my character, a vector 2 makes me going faster and faster so I did this:
if (Gdx.input.isKeyJustPressed(Input.Keys.W) && player.b2body.getLinearVelocity().y == 0)
player.b2body.applyLinearImpulse(new Vector2(0, 4f), player.b2body.getWorldCenter(), true);
if (Gdx.input.isKeyPressed(Input.Keys.D))
player.b2body.applyLinearImpulse(new Vector2(0.1f, 0), player.b2body.getWorldCenter(), true);
if (Gdx.input.isKeyPressed(Input.Keys.A))
player.b2body.applyLinearImpulse(new Vector2(-0.1f, 0), player.b2body.getWorldCenter(), true);
if (player.b2body.getLinearVelocity().x > 2) {
player.b2body.setLinearVelocity(2, player.b2body.getLinearVelocity().y);
}
else if (player.b2body.getLinearVelocity().x < -2) {
player.b2body.setLinearVelocity(-2, player.b2body.getLinearVelocity().y);
}
So the player has a maximum speed of two. But when he hits the ground he is slower for around a half second because he gets faste in the air. How ca I fix that?
And my second questin is: When I jump and press jump again right after I hit the goround the character doesnt jump! Why and how can I fix that?
Hope you can help me and thanks in advance!