Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个b2_dynamicBody我_body->ApplyForce在屏幕上移动的。
b2_dynamicBody
_body->ApplyForce
我如何找出它是向前还是向后移动?
我知道如何找出速度
b2Vec2 currentVelocity = _body->GetLinearVelocity(); float32 speed = currentVelocity.Normalize();
但不是向前或向后。
您还可以获得currentVelocity.Length()不改变值的速度。
currentVelocity.Length()
如果您将向前定义为从左到右(增加 X),那么如果 currentVelocity.x > 0 则您的身体向前移动,如果 x < 0 则向后移动。如果向前向上,则 y > 0 向前,y < 0 向后。
速度是一个向量,由大小和方向组成。通常,轴上的方向由值的符号指示。
如果身体相对速度的 y 部分为负,我会说你可以说身体正在向后移动。