Beispiel #1
0
    // Should be used as the default behaviour.
    public static void PositionAndShoot(GameObject player, GameObject ball, GameObject goal)
    {
        /* First a position of the goal is found, then player is rotated to face the ball.
         * Next distance from the player to the point from which he would be able to shoot is found.
         * Then the player is moved closer to it or uses a sword to shot at the goal. */
        AIMovementBehaviour.LookAt(player, ball);

        Vector2 goalDirection = AIDirectionBehaviour.FindPositionOf(ball, goal, 0.9f);                            // The point where player should position itself

        if (AICalculate.CalculateLengthBetween(player, ball.transform.position.x, ball.transform.position.y) < 2) // If player is close to the ball
        {
            if (AICalculate.CalculateLengthBetween(player, goalDirection.x, goalDirection.y) > 0.3)
            {
                PositionInFrontOf(player, ball, goal);
            }
            else
            {
                AIBasicBehaviour.UseSword(player);
            }
        }
        else
        {
            AIMovementBehaviour.MoveForward(player);
        }
    }
Beispiel #2
0
    public static void ShootInTheMiddle(GameObject player, GameObject ball, GameObject goal)
    {
        /* Same as ShootAtGoal method but this time the player kicks the towards the middle of
         * the football pitch.
         */
        Vector2 goalDirection = AIDirectionBehaviour.FindPositionOf(ball, goal, 0.9f);

        AIMovementBehaviour.LookAt(player, ball);
        if (AICalculate.CalculateLengthBetween(player, ball.transform.position.x, ball.transform.position.y) < 2) // If player is close to the ball
        {
            if (AICalculate.CalculateLengthBetween(player, goalDirection.x, goalDirection.y) > 0.3)
            {
                PositionInFrontOf(player, ball, goal);
            }
            else
            {
                AIMovementBehaviour.LookAt(player, player.transform.position.x, player.GetComponent <PlayerController>().globalSettings.stateBoundary);
                AIBasicBehaviour.UseSword(player);
            }
        }
        else
        {
            AIMovementBehaviour.MoveForward(player);
        }
    }
    public static Vector2 GetClosestPickup(List <PickupActivator> activePickups, int activeCount, GameObject player)
    {
        /* This method checks if there are any active pickups in the game by getting an active pickup list
         * from the main pickup list controller. Then it checks which one is the closest
         * and returns its position as a vector.
         */
        PickupActivator closestPickup   = null;
        float           closestDistance = 100;

        if (activeCount > 0)
        {
            for (int i = 0; i < activeCount; i++)
            {
                float distance = AICalculate.CalculateLengthBetween(player, activePickups[i].GetComponent <Transform>().position.x, activePickups[i].GetComponent <Transform>().position.y);
                if (distance < closestDistance)
                {
                    closestDistance = distance;
                    closestPickup   = activePickups[i];
                }
            }
        }

        if (closestPickup == null)
        {
            return(new Vector2(0, 0));
        }
        return(new Vector2(closestPickup.GetComponent <Transform>().position.x, closestPickup.GetComponent <Transform>().position.y));
    }
    public static bool CheckIfCloseToOpponent(GameObject player, GameObject opponent)
    {
        float distanceFromBall = AICalculate.CalculateLengthBetween(player, opponent);

        if (distanceFromBall < 2)
        {
            return(true);
        }
        return(false);
    }
    public static bool CheckIfBallApproaching(GameObject player, GameObject ball)
    {
        float distance = AICalculate.CalculateLengthBetween(player, ball);

        if (distance < 3 && distance > 2)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
 public static bool CheckIfCloseToPickup(List <PickupActivator> activePickups, GameObject player)
 {
     // Look for available pickups
     foreach (PickupActivator pickup in activePickups)
     {
         float distance = AICalculate.CalculateLengthBetween(player, pickup.GetComponent <Transform>().position.x, pickup.GetComponent <Transform>().position.y);
         if (distance < 5)
         {
             return(true);
         }
     }
     return(false);
 }
    public static bool FarFromBall(GameObject player, GameObject ball)
    {
        // Returns bool depending on the distance from the player to the ball.

        float distanceFromBall  = AICalculate.CalculateLengthBetween(player, ball);
        int   allowableDistance = player.GetComponent <PlayerController>().GetGlobalSettings().allowableDistanceFromBall;

        if (distanceFromBall > allowableDistance)
        {
            return(true);
        }
        return(false);
    }