开发者

Box2d SetLinearVelocity not working with gravity

开发者 https://www.devze.com 2023-02-11 17:58 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消