protected override void StartClimbingDown()
        {
            SetClimbingState();
            _controller.CollisionsOff();
            _controller.ResetColliderSize();

            // we rotate our character if requested
            if (ForceRightFacing)
            {
                _character.Face(Character.FacingDirections.Right);
            }

            if (_characterGravity != null)
            {
                if (_characterGravity.ShouldReverseInput())
                {
                    if (CurrentLadder.CenterCharacterOnLadder)
                    {
                        _corgiController.SetTransform(new Vector2(CurrentLadder.transform.position.x,
                                                                  transform.position.y + _climbingDownInitialYTranslation));
                    }
                    else
                    {
                        _corgiController.SetTransform(new Vector2(transform.position.x,
                                                                  transform.position.y + _climbingDownInitialYTranslation));
                    }

                    return;
                }
            }

            // we force its position to be a bit lower
            if (CurrentLadder.CenterCharacterOnLadder)
            {
                _corgiController.SetTransform(new Vector2(CurrentLadder.transform.position.x,
                                                          transform.position.y - _climbingDownInitialYTranslation));
            }
            else
            {
                _corgiController.SetTransform(new Vector2(transform.position.x,
                                                          transform.position.y - _climbingDownInitialYTranslation));
            }
        }
Exemplo n.º 2
0
        protected override void Grip()
        {
            // if we're gripping to something, we disable the gravity
            if (_movement.CurrentState == CharacterStates.MovementStates.Gripping)
            {
                _controller.SetForce(Vector2.zero);
                _controller.GravityActive(false);
                if (_characterJump != null)
                {
                    _characterJump.ResetNumberOfJumps();
                }

                _corgiController.SetTransform(_gripTarget.transform.position + _gripTarget.GripOffset);
            }
        }
Exemplo n.º 3
0
        public virtual void HandleWallWalking()
        {
            HorizontalMovement direction = MovementDirection;

            if (controller == null)
            {
                controller    = (CorgiControllerOverride)_controller;
                _boundsWidth  = controller.BoundsWidth;
                _boundsHeight = controller.BoundsHeight;
                _boundsDiff   = Mathf.Abs(_boundsWidth - _boundsHeight);
            }

            if (direction == HorizontalMovement.Left && _controller.State.IsCollidingLeft)
            {
                // shift position by difference between height / width to accommodate for pivot rotation
                controller.SetTransform(transform.position + transform.up * Mathf.Abs(_boundsDiff));

                RotateGravity(direction);

                // no longer colliding due to rotational shift
                _controller.State.IsCollidingLeft = false;
            }
            else if (direction == HorizontalMovement.Right && _controller.State.IsCollidingRight)
            {
                // shift position by difference between height / width to accommodate for pivot rotation
                controller.SetTransform(transform.position + -transform.up * Mathf.Abs(_boundsDiff));

                RotateGravity(direction);

                // no longer colliding due to rotational shift
                _controller.State.IsCollidingRight = false;
            }
            else if (IsOverLedge())
            {
                // whether player is on vertical or horizontal plane
                //bool isVertical = _defaultGravityAngle == 90 || _defaultGravityAngle == 270;

                RotateGravity((HorizontalMovement)(-(float)direction));

                Transition(true, GravityDirectionVector);

                // get forward direction depending which direction character is facing
                Vector3 forward = _character.IsFacingRight ? transform.right : -transform.right;

                Vector3 forwardAmount = (_boundsWidth * 0.5f * forward) + (_boundsWidth * ledgeCheckRayOffset) * forward + _boundsDiff * forward;
                Vector3 downAmount    = (_boundsWidth * 0.5f * -transform.up) + (_boundsWidth * ledgeCheckRayOffset * -transform.up);

                Vector3 newPosition = transform.position + downAmount + forwardAmount;

                // check whether rotation / position shift is safe
                Collider2D hit = CODebug.OverlapBox(newPosition, controller.BoxCollider.size, _defaultGravityAngle, controller.PlatformMask, Color.cyan);

                // if safe, perform shift
                if (hit == null)
                {
                    transform.localEulerAngles = new Vector3(0, 0, _defaultGravityAngle);

                    // shift character position by overhang extent
                    controller.SetTransform(newPosition);
                }
                else
                {
                    CODebug.DebugDrawBox(newPosition, controller.BoxCollider.size, _defaultGravityAngle, Color.white, 5f);
                    // reverse gravity change
                    RotateGravity((HorizontalMovement)((float)direction));
                }
            }
        }