Esempio n. 1
0
        private bool CheckLedgeWhileHanging()
        {
            Bounds bounds = _motor.Collider.bounds;

            const float checkWidth  = 3f;
            const float checkHeight = 3f;

            int layer = CurrentClimbingState.PivotCollider.gameObject.layer;

            float xValue = layer == _leftClimbLayer ? bounds.max.x - (checkWidth / 2) : bounds.min.x + (checkWidth / 2);
            float yValue = bounds.max.y + 1;

            var origin = new Vector3(xValue, yValue);
            var size   = new Vector2(checkWidth, 0.01f);

            RaycastHit2D[] hits = Physics2D.BoxCastAll(origin, size, 0, Vector2.up, checkHeight, GetClimbMask());
            hits = RemoveInvalidColliders(hits);

            var hit = hits.FirstOrDefault(h => EdgeValidator.CanJumpToHang(h.collider, bounds.center, _motor.StandingCollider));

            if (hit)
            {
                NextClimbingState = GetClimbingState(CurrentClimbingState.Climb, hit.collider);
                _anim.SetBool("inverted", ClimbSide == _motor.GetDirectionFacing());
            }
            return(hit);
        }