Box2d SetLinearVelocity not working with gravity

1.8k Views Asked by At

I have a body (player) in my box2d world.

Whenever I try to set its x velocity (every 2 seconds or whatever) and it is falling due to gravity, it jitters up and down.

I have also tried to set its y velocity equal to gravity (-30.0f) but then it does it even worse.

Tyvm.

1

There are 1 best solutions below

0
On BEST ANSWER

That's because you player is created as a dynamic body. So the gravity is applied to the player every simulation step causing he/she to change the velocity.

Put your player b2_kinematicBody - then no forces will be applied to it. If you still want the player to be dynamic apply force -playerMass*gravityVector each step (or set autoClearForces parameter of b2World to false and apply force once) to remove gravity force.