Esempio n. 1
0
    public void CheckForClimbingStairs()
    {
        if (playerStatusVariables.canClimbStairs && !playerStatusVariables.isClimbingStairs)
        {
            var collider = GetStairsTrigger();

            if (collider != null)
            {
                var stairsController = collider.GetComponent <StairsController>();


                if ((CheckIfObjectIsRight(stairsController.stairsCollider.transform.position)
                        ? playerController.HorizontalMove > 0
                        : playerController.HorizontalMove < 0) &&
                    (stairsController.stairsTriggerType == StairsTriggerType.TopTrigger
                        ? playerController.VerticalMovement < 0
                        : playerController.VerticalMovement > 0))
                {
                    SetOnStairsColliders(stairsController);
                }
            }
        }
        else if (playerStatusVariables.isClimbingStairs &&
                 (playerCollisionHandler.CheckForLayerCollision(LayerMask.GetMask("Ground"), 0.1f) ||
                  playerStatusVariables.isOnAir) &&
                 playerStatusVariables.canClimbStairs)
        {
            var collider = GetStairsTrigger();

            if (collider != null)
            {
                var stairsController = collider.GetComponent <StairsController>();

                var stairsCollider = stairsController.stairsCollider.GetComponent <BoxCollider2D>();

                //A normal é sempre perpendicular ao plano, porém é necessário manter a rotação entre 29 e -29
                var normal = stairsCollider.transform.up;
                if (CheckIfObjectIsRight(stairsController.stairsCollider.transform.position)
                    ? PhysicsHelpers.SlopeInclinationRight(normal)
                        ? rigidbody2D.velocity.y < 0
                        : rigidbody2D.velocity.y >= 0
                    : PhysicsHelpers.SlopeInclinationRight(normal)
                        ? rigidbody2D.velocity.y >= 0
                        : rigidbody2D.velocity.y < 0)
                {
                    playerStatusVariables.isClimbingStairs = false;

                    PhysicsHelpers.IgnoreCollision(capsuleCollider2D, stairsController.adjacentCollider, false);
                    stairsController.adjacentCollider.gameObject.layer = LayerMask.NameToLayer("Ground");
                }
            }
        }
    }