コード例 #1
0
        public override void OnStateEnter(MyMovementState previousState)
        {
            KinematicCharacterMotor.HandlePhysics(false, true);
            _climbingState = ClimbingState.Anchoring;

            // Store the target position and rotation to snap to
            _targetPosition = ActiveLadder.ClosestPointOnLadderSegment(KinematicCharacterMotor.TransientPosition, out _onLadderSegmentState);
            _targetRotation = ActiveLadder.transform.rotation;
        }
コード例 #2
0
        public override void AfterCharacterUpdate(float deltaTime)
        {
            switch (_climbingState)
            {
            case ClimbingState.Climbing:
                // Detect getting off ladder during climbing
                ActiveLadder.ClosestPointOnLadderSegment(KinematicCharacterMotor.TransientPosition, out _onLadderSegmentState);
                if (Mathf.Abs(_onLadderSegmentState) > 0.05f)
                {
                    _climbingState = ClimbingState.DeAnchoring;

                    // If we're higher than the ladder top point
                    if (_onLadderSegmentState > 0)
                    {
                        _targetPosition = ActiveLadder.TopReleasePoint.position;
                        _targetRotation = ActiveLadder.TopReleasePoint.rotation;
                    }
                    // If we're lower than the ladder bottom point
                    else if (_onLadderSegmentState < 0)
                    {
                        _targetPosition = ActiveLadder.BottomReleasePoint.position;
                        _targetRotation = ActiveLadder.BottomReleasePoint.rotation;
                    }
                }
                break;

            case ClimbingState.Anchoring:
            case ClimbingState.DeAnchoring:
                // Detect transitioning out from anchoring states
                if (_anchoringTimer >= AnchoringDuration)
                {
                    if (_climbingState == ClimbingState.Anchoring)
                    {
                        _climbingState = ClimbingState.Climbing;
                    }
                    else if (_climbingState == ClimbingState.DeAnchoring)
                    {
                        AssignedCharacterController.TransitionToState(AssignedCharacterController.DefaultMovementState);
                    }
                }

                // Keep track of time since we started anchoring
                _anchoringTimer += deltaTime;
                break;
            }
        }