// Sets the aerial state to ThirdPersonAerialMovementState.Falling and fires the event. // NOTE: This subscribes to ControllerAdapter.startedFalling void OnStartedFalling(float predictedFallDistance) { // check if far enough from ground to enter fall state if (m_ControllerAdapter.IsPredictedFallShort()) { m_TrackGroundHeight = true; return; } m_TrackGroundHeight = false; if (m_AerialState == ThirdPersonAerialMovementState.Grounded) { cachedForwardVelocity = m_AverageForwardVelocity.average; } m_ControllerAdapter.SetFallVelocity(); m_AerialState = ThirdPersonAerialMovementState.Falling; m_FallDirection = CalculateLocalInputDirection(); if (fallStarted != null) { fallStarted(predictedFallDistance); } }
// Sets the aerial state to ThirdPersonAerialMovementState.Grounded and clears 'm_AverageForwardVelocity' if no input. void OnLanding() { m_AerialState = ThirdPersonAerialMovementState.Grounded; if (!m_CharacterInput.hasMovementInput) { m_AverageForwardVelocity.Clear(); } m_PreviousInputs.Clear(); }
// Attempts a jump. If successful fires the 'jumpStarted' event and sets 'm_AerialState' to ThirdPersonAerialMovementState.Jumping // reattempt: Whether a jump should be reattempted void TryJump(out bool reattempt) { if (m_MovementState == ThirdPersonGroundMovementState.TurningAround || m_ThirdPersonBrain.animatorState == ThirdPersonBrain.AnimatorState.Landing || m_ThirdPersonBrain.animatorState == ThirdPersonBrain.AnimatorState.JumpLanding) { reattempt = true; return; } if (!IsGrounded || m_ControllerAdapter.startedSlide || !m_ThirdPersonBrain.isRootMotionState) { reattempt = false; return; } m_AerialState = ThirdPersonAerialMovementState.Jumping; m_FallDirection = CalculateLocalInputDirection(); // If an idle forward jump is detected update the normalized speeds to represent a forward jump and pass // them on to the ThirdPersonBrain. if (IsIdleForwardJump()) { cachedForwardVelocity = m_Configuration.standingJumpSpeed; if (movementMode == ThirdPersonMotorMovementMode.Exploration) { normalizedForwardSpeed = 1.0f; } else { normalizedLateralSpeed = m_CharacterInput.moveInput.x; normalizedForwardSpeed = m_CharacterInput.moveInput.y; m_ThirdPersonBrain.UpdateLateralSpeed(normalizedLateralSpeed, 1.0f); } m_ThirdPersonBrain.UpdateForwardSpeed(normalizedForwardSpeed, 1.0f); } else { cachedForwardVelocity = m_AverageForwardVelocity.average; } if (Mathf.Abs(normalizedLateralSpeed) >= 0.8f) { cachedForwardVelocity *= m_Configuration.lateralStrafeJumpMultiplier; } m_ControllerAdapter.SetJumpVelocity( m_Configuration.jumpHeightAsFactorOfForwardSpeed.Evaluate(normalizedForwardSpeed)); if (jumpStarted != null) { jumpStarted(); } reattempt = false; }