Пример #1
0
        private void UpdateBallDirAndSpeed(float ticksToTravel)
        {
            Vector2 endPos = mRoad.RoadSegmentEndPos(mCurrentRoadSegment);
            Vector2 dir    = endPos - Center;

            VelocityDirection = dir;

            // amount of time we have to travel the remaining of the road segment
            float totalLength  = mRoad.RoadSegmentLength(mCurrentRoadSegment);
            float remainLehgth = dir.Length();
            float percentLeft  = remainLehgth / totalLength;
            float ticksLeft    = ticksToTravel * percentLeft;

            Speed = remainLehgth / ticksLeft;
        }
Пример #2
0
        private void UpdateCarDirAndSpeed()
        {
            Vector2 targetDir = mRoad.RoadSegmentEndPos(mCurrentRoadSegment) - Center;

            targetDir.Normalize();

            float theta = (float)((180.0 / Math.PI) *
                                  Math.Acos((double)Vector2.Dot(FrontDirection, targetDir)));

            if (theta > 0.001f)
            { // if not already in the same direction
                Vector3 myDir3     = new Vector3(FrontDirection, 0f);
                Vector3 targetDir3 = new Vector3(targetDir, 0f);
                Vector3 sign       = Vector3.Cross(myDir3, targetDir3);

                RotateAngle      += Math.Sign(sign.Z) * theta * mTurnRate;
                VelocityDirection = FrontDirection;
            }
        }