xcode 如何在box2d中停止作用在身体上的力
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7543764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to stop the forces acting on a body in box2d
提问by user891123
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?
我在 iphone 上使用 box2d 来创建一个游戏。我有一个受重力影响向下移动而不是向右或向左移动的身体。它会被另一个物体击中,然后向右或向左移动。然后我有一个重置按钮,可以将身体移回起点。唯一的问题是它仍在向右或向左移动。我怎样才能抵消球已经在移动的力?当我重置游戏时,如何摆脱这种左右运动?
回答by Andrew
box2d automatically clears forces each simulation step. I think you are just changing you body's position when reseting, but not it's velocity. Add this code to your reset method:
box2d 自动清除强制每个模拟步骤。我认为您只是在重置时改变了身体的位置,而不是速度。将此代码添加到您的重置方法中:
body->SetLinearVelocity(b2Vec2(0,0));
body->SetAngularVelocity(0);