Box2d SetLinearVelocity 不适用于重力
我的 box2d 世界中有一个身体(玩家)。
每当我尝试设置它的 x 速度(每 2 秒或其他)并且它由于重力而下落时,它就会上下抖动。
我还尝试将其 y 速度设置为等于重力 (-30.0f),但结果更糟。
泰沃姆。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是因为你的玩家被创建为一个动态的身体。因此,每个模拟步骤都会向玩家施加重力,导致他/她改变速度。
将您的玩家放入
b2_kinematicBody
- 那么就不会对其施加任何力。如果您仍然希望玩家是动态的,请在每一步施加力-playerMass*gravityVector
(或将 b2World 的 autoClearForces 参数设置为 false 并施加一次力)以消除重力。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.