Hi,
I need to check the velocity of a b2Body, in the direction it is facing. So if the body is moving forwards it would be positive, if it is moving perfectly laterally, it would be zero, and if any velocity is away from the direction the b2Body is facing, it is negative.
I can calculate the length of the vector, but the length is obviously always positive...and I need to know the component of the velocity in terms of the direction.
// Get the linear velocity vector of the body
b2Vec2 linearVelocity = body_->GetLinearVelocity();
_currentLinearVelocity = linearVelocity.Length();
//now find out the velocity component in the direction of the bodies rotation
b2Vec2 facingVelocity = body_->GetTransform().R.col2;
facingVelocity *= b2Dot(linearVelocity, facingVelocity);
_currentForwardVelocity = facingVelocity.Length(); // this is always positive...after all, a length is always positive
CCLOG(@"--->>>--->>> VELOCITY IN FACING DIRECTION OF SHIP IS %f", _currentForwardVelocity);
CCLOG(@"--->>>--->>> Linear Velocity OF SHIP IS %f", _currentLinearVelocity);
b2Vec2 thrustVec = body_->GetTransform().R.col2;
thrustVec *= _thrustForce;
body_->ApplyForce(thrustVec, body_->GetPosition());
as always, any advice appreciated.
Regards
i