void TestTank::MoveInHeadingDirection(float deltaTime) { mSteeringForce = mSteering->Calculate(deltaTime); //cout << mSteeringForce.x << ":" << mSteeringForce.y << endl; //Acceleration = Force/Mass Vector2D acceleration = mSteeringForce / GetMass(); //Update velocity. mVelocity += acceleration * deltaTime; //Don't allow the tank does not go faster than max speed. mVelocity.Truncate(GetMaxSpeed()); if (mVelocity.Length() > 0.0001) { if (mVelocity.x != mVelocity.x || mVelocity.y != mVelocity.y) return; Vector2D newPosition = GetPosition(); newPosition.x += mVelocity.x*deltaTime; newPosition.y += (mVelocity.y)*deltaTime; //Y flipped as adding to Y moves down screen. SetPosition(newPosition); Vector2D ahead = Vec2DNormalize(mVelocity); if (ahead.Length() == 0) ahead = mHeading; Vector2D cenPos = GetCentrePosition(); Vector2D aheadDistance = cenPos + ahead * 30; RotateHeadingToFacePosition(aheadDistance); } }
void PlayerBase::TrackBall() { RotateHeadingToFacePosition(Ball()->Pos()); }