How do I move player with keyboard without applying forces? If I do
playerBody.setLinearVelocity(new B2Vec2(0, 2)) it moves the player but when I release the key for movement, the ball is continuously moving for few seconds.
Applying a force still the way to do it. But instead, you can apply directly the impulse for the desired speed. You can still make the player instantly stop (instead of decelerating) You just need to set the desired speed to zero. Here's the snippet:
If you want gradual acceleration, change the switch block by:
You should be fine with this.
Depending on what you want to do, you can use
so while you have your key pressed down you can keep increasing your position by 1 or something.
or when the key is down you can apply the linear velocity and when the key is up you can set the linear velocity and to 0.
The velocity will always be moving the body until the forces in the world acting against the reduce the velocity to 0;