예제 #1
0
        private Controller KickOffFrontCorner(float dt)
        {
            float distance = (new Vector2(car.Position.X, car.Position.Y) - new Vector2(0, 0)).Length();

            Controller controller = new Controller();

            if (car.Velocity.Length() < 1000)
            {
                controller.Boost = true;

                Vector3 local = Vector3.Transform(-car.Position, Quaternion.Inverse(car.Rotation));
                controller.Steer = MathUtility.Clip((float)Math.Atan2(local.Y, local.X) * 0.5f, -1, 1);
            }
            else if (distance > 2400)
            {
                if (dodge == null)
                {
                    dodge = new Dodge(car, 0.13f, new Vector2(-1, 0));
                }

                controller = dodge.Step(dt);

                controller.Boost = true;
            }
            else if (distance > 500)
            {
                Vector3 local = Vector3.Transform(-car.Position, Quaternion.Inverse(car.Rotation));
                controller.Steer = MathUtility.Clip((float)Math.Atan2(local.Y, local.X) * 10, -1, 1);

                controller.Boost = distance < 2000 && car.HasWheelContact;

                dodge = null;
            }
            else
            {
                if (dodge == null)
                {
                    Vector3 local = Vector3.Normalize(Vector3.Transform(-car.Position, Quaternion.Inverse(car.Rotation)));
                    dodge = new Dodge(car, 0.2f, new Vector2(-local.X, local.Y));
                }

                controller = dodge.Step(dt);
            }


            controller.Throttle = 1; // No reason not to hold throttle.

            return(controller);
        }
예제 #2
0
        private Controller KickOffBackCorner(float dt)
        {
            Controller c = new Controller();

            if (Math.Abs(car.Position.Y) > 3200)
            {
                c.Boost = true;

                Vector3 local = Vector3.Transform(new Vector3(0, Math.Sign(car.Position.Y) * 3000, 0) - car.Position, Quaternion.Inverse(car.Rotation));
                c.Steer = MathUtility.Clip((float)Math.Atan2(local.Y, local.X), -1f, 1f);
            }
            else if (Math.Abs(car.Position.Y) > 1500)
            {
                Vector3 local = Vector3.Transform(new Vector3(Math.Sign(car.Position.X) * 3500, 0, 0) - car.Position, Quaternion.Inverse(car.Rotation));
                local.Z = 0;
                local   = Vector3.Normalize(local);

                if (dodge == null)
                {
                    dodge = new Dodge(car, 0.15f, new Vector2(-local.X, local.Y));
                }

                c = dodge.Step(dt);

                c.Boost = Math.Abs(car.Position.Y) > 2600;
            }
            else if (Math.Abs(car.Position.Y) > 500)
            {
                dodge = null;
            }
            else
            {
                Vector3 local = Vector3.Transform(-car.Position, Quaternion.Inverse(car.Rotation));

                if (dodge == null)
                {
                    dodge = new Dodge(car, 0.15f, new Vector2(-1, 0));
                }

                c = dodge.Step(dt);
            }

            c.Throttle = 1.0f; // No reason not to hold throttle.

            return(c);
        }
예제 #3
0
        private Controller KickOffCenter(float dt)
        {
            Controller controller = new Controller();

            if (Math.Abs(car.Position.Y) > 3700) // Boost in a straight line.
            {
                controller.Boost = true;
            }
            else if (Math.Abs(car.Position.Y) > 1000) // Dodge forward.
            {
                if (dodge == null)
                {
                    dodge = new Dodge(car, 0.2f, new Vector2(-1, 0));
                }

                controller = dodge.Step(dt);

                controller.Boost = Math.Abs(car.Position.Y) > 3000; // Make sure we keep boosting during the first part of the dodge.
            }
            else if (Math.Abs(car.Position.Y) > 700)
            {
                dodge = null;
            }
            else // Final dodge when we are close to the ball.
            {
                if (dodge == null)
                {
                    dodge = new Dodge(car, 0.2f, new Vector2(-1, 0));
                }

                controller = dodge.Step(dt);
            }

            controller.Throttle = 1; // No reason not to hold throttle.

            return(controller);
        }