如何在 box2d 中停止作用在物体上的力
我正在 iPhone 上使用 box2d 来创建游戏。我的身体受重力影响向下移动,而不是向右或向左移动。它会被另一个物体击中,然后向右或向左移动。然后我有一个重置按钮,可以将身体移回到起点。唯一的问题是它仍在向右或向左移动。如何抵消球已经行进的力?当我重置游戏时,如何摆脱这种左右移动?
I am using box2d on the iphone to create a game. I have a body that is effected by gravity to move down and not right or left. It will get hit by another body and will then be moving right or left. I then have a reset button which moves the body back to its starting point. The only problem is that it is still moving right or left. How can I counteract the forces that a ball is already traveling? How can I get rid of this right and left movement when I reset my game?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Box2d 自动清除每个模拟步骤的力。我认为你在重置时只是改变了身体的位置,而不是它的速度。将此代码添加到您的重置方法中:
Box2d automatically clears the forces each simulation step. I think you are just changing your body's position when resetting, but not its velocity. Add this code to your reset method: