So I am making a top down game where the player moves using WASD keys. For this I use
if (Gdx.input.isKeyPressed(Input.Keys.S) && b2dBody.getLinearVelocity().y >= -0.8) {
b2dBody.applyLinearImpulse(new Vector2(0, -PLAYER_SPEED), b2dBody.getWorldCenter(), true);
} else if (Gdx.input.isKeyPressed(Input.Keys.W) && b2dBody.getLinearVelocity().y <= 0.8) {
b2dBody.applyLinearImpulse(new Vector2(0f, PLAYER_SPEED), b2dBody.getWorldCenter(), true);
} else if (Gdx.input.isKeyPressed(Input.Keys.A) && b2dBody.getLinearVelocity().x >= -0.8) {
b2dBody.applyLinearImpulse(new Vector2(-PLAYER_SPEED, 0), b2dBody.getWorldCenter(), true);
} else if (Gdx.input.isKeyPressed(Input.Keys.D) && b2dBody.getLinearVelocity().x <= 0.8) {
b2dBody.applyLinearImpulse(new Vector2(PLAYER_SPEED, 0), b2dBody.getWorldCenter(), true);
}
But because the gravity is set to 0 world = new World(new Vector2(0, 0), true);
the body doesn't stop. I was wondering if there was a way to keep the gravity the same while making the body stop after after a while? Thanks in advance.