Box2d SetLinearVelocity not working with gravity
I have a body (player) in my box2d world.
Whenever I try to set its x velo开发者_运维问答city (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.
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.
精彩评论