コード例 #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);
        }
    }
コード例 #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);
        }
    }
コード例 #3
0
    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));
    }
コード例 #4
0
    public static bool CheckIfCloseToOpponent(GameObject player, GameObject opponent)
    {
        float distanceFromBall = AICalculate.CalculateLengthBetween(player, opponent);

        if (distanceFromBall < 2)
        {
            return(true);
        }
        return(false);
    }
コード例 #5
0
    public static bool CheckIfBallApproaching(GameObject player, GameObject ball)
    {
        float distance = AICalculate.CalculateLengthBetween(player, ball);

        if (distance < 3 && distance > 2)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
コード例 #6
0
 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);
 }
コード例 #7
0
    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);
    }
コード例 #8
0
    public static void PositionInFrontOf(GameObject player, GameObject ball, GameObject goal)
    {
        /* This method position the player in front of the given object.
         * It is mainly used to position the player in front of the ball in such a way that the ball is
         * between the player and the goal.
         */

        Vector2 coordinates = AICalculate.FindPointBetween(player, ball, goal);

        /* Now we know what is the position of the point that the player will move towards.
         * Next we need to move the player towards that point.
         * MoveTowards does not require the player character to look in the
         * certain direction so looking and moving can be done separately.
         */
        AIMovementBehaviour.MoveTowards(player, coordinates.x, coordinates.y);
    }