/// <summary> /// This exists as part of the IMovable interface. It is used to move the kart to a specific position for example to replace it when the kart falls off the track. /// </summary> public void ForceMove(Vector3 positionDelta, Quaternion rotationDelta) { m_Velocity = Vector3.zero; m_DriftState = DriftState.NotDrifting; m_RepositionPositionDelta = positionDelta; m_RepositionRotationDelta = rotationDelta; }
/// <summary> /// Starts a drift if the kart lands with a sufficient turn. /// </summary> void StartDrift(GroundInfo currentGroundInfo, GroundInfo nextGroundInfo, Quaternion rotationStream) { if (m_Input.HopHeld && !currentGroundInfo.isGrounded && nextGroundInfo.isGrounded && m_HasControl && m_DriftState == DriftState.NotDrifting) { Vector3 kartForward = rotationStream * Vector3.forward; kartForward.y = 0f; kartForward.Normalize(); Vector3 flatVelocity = m_Velocity; flatVelocity.y = 0f; flatVelocity.Normalize(); float signedAngle = Vector3.SignedAngle(kartForward, flatVelocity, Vector3.up); if (signedAngle > minDriftStartAngle && signedAngle < maxDriftStartAngle) { m_DriftOffset = Quaternion.Euler(0f, signedAngle, 0f); m_DriftState = DriftState.FacingLeft; OnDriftStarted.Invoke(); } else if (signedAngle < -minDriftStartAngle && signedAngle > -maxDriftStartAngle) { m_DriftOffset = Quaternion.Euler(0f, signedAngle, 0f); m_DriftState = DriftState.FacingRight; OnDriftStarted.Invoke(); } } }
/// <summary> /// Stops a drift if the hop input is no longer held. /// </summary> void StopDrift(float deltaTime) { m_DriftOffset = Quaternion.RotateTowards(m_DriftOffset, Quaternion.identity, rotationCorrectionSpeed * deltaTime); m_DriftState = DriftState.NotDrifting; OnDriftStopped.Invoke(); }
private void EnterNextState() { _hasTurnedOtherSide = false; _driftedLongEnough = false; switch (DriftState) { case DriftState.NotDrifting: DriftState = DriftState.White; OnDriftWhite.Invoke(); break; case DriftState.White: DriftState = DriftState.Orange; OnDriftOrange.Invoke(); break; case DriftState.Orange: DriftState = DriftState.Red; OnDriftRed.Invoke(); break; case DriftState.Red: break; } _driftedLongEnoughTimer = StartCoroutine(DriftTimer()); }
/// <summary> /// Stops a drift if the hop input is no longer held. /// </summary> void StopDrift(float deltaTime) { if (!m_Input.HopHeld || !m_HasControl) { m_DriftOffset = Quaternion.RotateTowards(m_DriftOffset, Quaternion.identity, rotationCorrectionSpeed * deltaTime); m_DriftState = DriftState.NotDrifting; OnDriftStopped.Invoke(); } }
public void ResetDrift() { DriftTurnState = TurnState.NotTurning; DriftState = DriftState.NotDrifting; OnDriftReset.Invoke(); _driftedLongEnough = false; if (_driftedLongEnoughTimer != null) { StopCoroutine(_driftedLongEnoughTimer); } }
private void OnDriftStateChange(DriftState oldDrift, DriftState newDrift) { if (newDrift == DriftState.Drifting) { Debug.Log("wd_漂移中"); Context.Controllers.Get <PlayerDriftController>().InputDrift(true); } else { Debug.Log("wd_漂移结束"); Context.Controllers.Get <PlayerDriftController>().InputDrift(false); } }
/// <summary> /// This exists as part of the IMovable interface. Typically it is called by the TrackManager when the kart finishes its final lap. /// </summary> public void DisableControl() { m_HasControl = false; m_DriftState = DriftState.NotDrifting; }