Example #1
0
    protected override float getHorizontalDirection()
    {
        // If you see the player, walk toward the player (but only up until your shooting range).
        // Otherwise, just patrol normally.
        Vector2 playerPosition = PlayerChain.Instance.transform.position;
        Vector2 position       = this.transform.position;

        float distanceXToPlayer = Mathf.Abs(playerPosition.x - position.x);
        float distanceYToPlayer = Mathf.Abs(playerPosition.y - position.y);

        if (PlayerChain.Instance.players.Count > 0 &&
            distanceXToPlayer < visionRange &&
            distanceYToPlayer < 1)
        {
            patrolling = false;
            float direction = (playerPosition.x - position.x) / (Mathf.Abs(playerPosition.x - position.x));

            // Stop if you're on a ledge or if you're within shooting range
            if (distanceXToPlayer < shootingRange && distanceYToPlayer < shootingRange)
            {
                return(0);
            }

            bool leftGround;
            bool rightGround;
            PhysicsUtl.LedgeCheck(collider2D, out leftGround, out rightGround);

            if (direction < 0 && !leftGround)
            {
                return(0);
            }
            else if (direction > 0 && !rightGround)
            {
                return(0);
            }

            return(direction);
        }
        else
        {
            patrolling = true;
            return(base.getHorizontalDirection());
        }
    }
Example #2
0
    protected override float getHorizontalDirection()
    {
        // If you see the player, walk toward the player. Otherwise, just patrol
        // normally.
        Vector2 playerPosition = PlayerChain.Instance.transform.position;
        Vector2 position       = this.transform.position;

        float distanceXToPlayer = Mathf.Abs(playerPosition.x - position.x);
        float distanceYToPlayer = Mathf.Abs(playerPosition.y - position.y);

        if (PlayerChain.Instance.players.Count > 0 &&
            distanceXToPlayer < visionRange &&
            distanceYToPlayer < 1)
        {
            patrolling = false;
            float direction = (playerPosition.x - position.x) / (Mathf.Abs(playerPosition.x - position.x));

            // If on a ledge, yolo jump!
            bool leftGround;
            bool rightGround;
            PhysicsUtl.LedgeCheck(collider2D, out leftGround, out rightGround);

            if (direction < 0 && !leftGround)
            {
                jump = true;
            }
            else if (direction > 0 && !rightGround)
            {
                jump = true;
            }

            // Stop jumping (mimic keypress for the full jump parabola)
            StartCoroutine(FinishJump());

            return(direction);
        }
        else
        {
            patrolling = true;
            return(base.getHorizontalDirection());
        }
    }
Example #3
0
    protected override float getHorizontalDirection()
    {
        // Patrol in a random direction
        //flipRandomDirection();

        // Stop if you're on a ledge
        bool leftGround;
        bool rightGround;

        PhysicsUtl.LedgeCheck(collider2D, out leftGround, out rightGround);

        float directionToReturn = direction;

        if (direction < 0 && !leftGround)
        {
            directionToReturn = 0;
        }
        else if (direction > 0 && !rightGround)
        {
            directionToReturn = 0;
        }

        return(directionToReturn);
    }