public static double WheelTurnForEndZeroWheelTurnToPoint(this PCar car, Vector point, double finalAngle, double sign)
        {
            PCar physicCar = new PCar(car);

            int                 ticks      = (int)Math.Abs(Math.Round(physicCar.WheelTurn / game.CarWheelTurnChangePerTick));
            AngleReachEvent     angleReach = new AngleReachEvent(finalAngle);
            MoveToAngleFunction mover      = new MoveToAngleFunction(finalAngle);

            for (int i = 0; i < ticks; i++)
            {
                mover.Iteration(physicCar, 1);
                if (angleReach.Check(physicCar))
                {
                    break;
                }
            }

            Vector dir = physicCar.Speed.Length < 1 ? physicCar.Dir : physicCar.Dir * 0.8 + physicCar.Speed.Normalize() * 0.2;

            double distance = -(point - physicCar.Pos).Cross(dir);

            if (Math.Abs(distance) < 10)
            {
                return(0);
            }

            return(car.WheelTurn + sign * game.CarWheelTurnChangePerTick * Math.Sign(distance));
        }
Esempio n. 2
0
        private bool isMovedOutFromLine(PCar iterCar, Vector needDirAngle)
        {
            if (outLineEvent.OutLine(iterCar))
            {
                return(false);
            }

            MoveToPoint mover = null;

            if (null != needPos)
            {
                mover = new MoveToPoint(needPos, needDirAngle.Angle);
            }
            else
            {
                mover = new MoveToPoint(defaultPos);
            }

            PCar carToAngle = new PCar(iterCar);
            MoveToAngleFunction moveToAngle = new MoveToAngleFunction(needDirAngle.Angle);
            int ticksToAngle = 0;

            for (; ticksToAngle < 100; ticksToAngle++)
            {
                moveToAngle.Iteration(carToAngle, 1);
                if (angleReachEvent.Check(carToAngle))
                {
                    break;
                }
            }

            PCar car = new PCar(iterCar);

            mover.Iteration(car, ticksToAngle);

            return(outLineEvent.OutLine(car));
        }