/// <summary> /// Begins decelerating the <see cref="Target"/> based on any opposing drag forces. /// </summary> /// <returns>An Enumerator to manage the running state of the Coroutine.</returns> protected virtual IEnumerator BeginDeceleration() { while (!Velocity.ApproxEquals(Vector3.zero, NilVelocityTolerance) || !AngularVelocity.ApproxEquals(Vector3.zero, NilAngularVelocityTolerance)) { Velocity = Vector3.Slerp(Velocity, Vector3.zero, Drag * Time.deltaTime); AngularVelocity = Vector3.Slerp(AngularVelocity, Vector3.zero, AngularDrag * Time.deltaTime); Target.transform.localRotation *= Quaternion.Euler(AngularVelocity); Target.transform.localPosition += Velocity * Time.deltaTime; yield return(null); } decelerationRoutine = null; Velocity = Vector3.zero; AngularVelocity = Vector3.zero; }
/// <inheritdoc /> public virtual void Process() { if (!canProcess) { return; } if (!Velocity.ApproxEquals(Vector3.zero, NilVelocityTolerance) || !AngularVelocity.ApproxEquals(Vector3.zero, NilAngularVelocityTolerance)) { float deltaTime = Time.inFixedTimeStep ? Time.fixedDeltaTime : Time.deltaTime; Velocity = Vector3.Lerp(Velocity, Vector3.zero, Drag * deltaTime); AngularVelocity = Vector3.Lerp(AngularVelocity, Vector3.zero, AngularDrag * deltaTime); Target.transform.localRotation *= Quaternion.Euler(AngularVelocity); Target.transform.localPosition += Velocity * deltaTime; } else { Velocity = Vector3.zero; AngularVelocity = Vector3.zero; canProcess = false; } }