本文介绍了如何在Box2D实体上施加恒定的力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone制作Box2d游戏。我需要在代表我的主要角色的身体上施加力。主体实际上是使用旋转关节连接的圆形上方的矩形。我将其用作应该在游戏中运行的角色的骨架(对此也有任何建议或反馈)。



我需要不断施加力量,以使他继续前进。最好的方法是什么?



我目前在tick方法中应用线速度。

  _world-> Step(dt,10,10); 

if(gamestarted)
{
b2Vec2 force = b2Vec2(6,-3);
_bottomBody-> SetLinearVelocity(force);
}

但是这种力量会不断增加并加速身体吗?

解决方案

似乎很简单:

  _bottomBody- > ApplyForce(force,_bottomBody-> GetPosition()); 

如果在每一步中都施加该力,则身体将朝着力矢量的方向加速。 / p>

I am making a Box2d game for the iPhone. I need to apply a force on a body which represents my main character. The body is actually a rectangle on top of a circle connected using a revolute joint. I am using this as the skeleton for my character who is supposed to be running through the game(any suggestions or feedback on this too would be appreciated).

I need a force to be applied continuously so that it keeps him moving. What would be the best way to do this?

I am currently applying linear velocity inside the tick method.

_world->Step(dt, 10, 10);

if(gamestarted)
{
    b2Vec2 force = b2Vec2(6, -3);
    _bottomBody->SetLinearVelocity(force);
}

But will this force keep adding up and accelerate the body?

解决方案

Seems simple:

_bottomBody->ApplyForce(force, _bottomBody->GetPosition());

If you apply that force in every step the body will accelerate in the direction of the force vector.

这篇关于如何在Box2D实体上施加恒定的力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 15:59