Ejemplo n.º 1
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);
        }
    }
Ejemplo n.º 2
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);
        }
    }
Ejemplo n.º 3
0
    public static Vector2 GoRoundTheBall(GameObject ball, GameObject goal)
    {
        double  goalAngle = AIDirectionBehaviour.GetRadian(ball, goal, 1);
        Vector2 des       = AIDirectionBehaviour.GetDirectionVector(goalAngle);

        return(AIDirectionBehaviour.FindPositionOf(ball, des));
    }
Ejemplo n.º 4
0
    public static Vector2 FindPointBetween(GameObject player, GameObject ball, GameObject goal)
    {
        /* First find the angle from the ball to the player (playerAngle),
         * and from the ball to the goal (goalAngle).
         * These points are used to guide the player around the ball thus, a counter
         * value is needed, in this case r that goes from 0 to 1.
         * The position of the point in which the player should move will keep circling
         * the ball. Imagine an arrow a few pixels away from the ball, playerAngle would make it
         * point in the direction of the player, and goalAngle would make it point
         * to the goal (we want to move player to the other side of that point so the ball is
         * between the player and the goal). */

        double goalRadian   = AIDirectionBehaviour.GetRadian(ball, goal, 1);
        double playerRadian = AIDirectionBehaviour.GetRadian(ball, player, -1);
        float  counter      = player.GetComponent <Counter>().a;

        /* To make sure that if the player (AI) is "under" the ball, it does not circle
         * the whole ball to get to the goalAngle position, this part was needed.
         * Since the bottom (0, -1) of the ball is 0 going to the left or 6.3 going to the right
         * i.e. the point where the angle resets, 6.3 is added to move that point to the left
         * side of the ball. */

        Vector2 playerDes = AIDirectionBehaviour.GetDirectionVector(playerRadian);
        Vector2 playerPos = AIDirectionBehaviour.FindPositionOf(ball, playerDes);

        if (playerPos.x > player.transform.position.x && playerPos.y > player.transform.position.y)
        {
            playerRadian += 6.3;
        }
        float   newRadian = (float)playerRadian * (1 - counter) + (float)goalRadian * counter;
        Vector2 des       = AIDirectionBehaviour.GetDirectionVector(newRadian, 1.2f);
        Vector2 pos       = AIDirectionBehaviour.FindPositionOf(ball, des);

        return(new Vector2(pos.x, pos.y));
    }
Ejemplo n.º 5
0
    public static Vector2 AvoidTheBall(GameObject player, GameObject ball, GameObject goal, float r)
    {
        // Probably useless

        /* First the angle from the ball to the goal and from the ball to the player is
         * needed. The GetAngle method returns a double with the direction.
         * Next a new angle is found which is a point between the goalAngle and
         * the playerAngle depending on the position of r. r is a float value that keeps going
         * from 0 to 1. Constantly updating these values makes the nAngle position to change
         * and circle around the ball between the goalAngle and the playerAngle.
         * Lastly the double is converted to radians and then the actual position
         * is found by using the FindPositionOf method.
         */
        double goalAngle   = AIDirectionBehaviour.GetRadian(ball, goal, 1);
        double playerAngle = AIDirectionBehaviour.GetRadian(ball, player, -1);

        float nAngle = (float)playerAngle * (1 - r) + (float)goalAngle * r;

        Vector2 des = AIDirectionBehaviour.GetDirectionVector(nAngle, 2 - (r));

        return(AIDirectionBehaviour.FindPositionOf(ball, des));
    }