1

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.

Daniel Node.js
  • 6,734
  • 9
  • 35
  • 57

1 Answers1

1

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.

Andrew
  • 24,218
  • 13
  • 61
  • 90