Quaternion SpringRotation(Quaternion current, Quaternion target) { var v_current = current.ToVector4(); var v_target = target.ToVector4(); _vrotation = ETween.Step(_vrotation, Vector4.zero, 1 + _rotationSpeed * 0.5f); _vrotation += (v_target - v_current) * (_rotationSpeed * 0.1f); return (v_current + _vrotation * Time.deltaTime).ToNormalizedQuaternion(); }
public static Quaternion Step( Quaternion current, Quaternion target, ref Vector4 velocity, float omega) { var vcurrent = current.ToVector4(); var vtarget = target.ToVector4(); // We can use either of vtarget/-vtarget. Use closer one. if (Vector4.Dot(vcurrent, vtarget) < 0) vtarget = -vtarget; var dt = Time.deltaTime; var n1 = velocity - (vcurrent - vtarget) * (omega * omega * dt); var n2 = 1 + omega * dt; velocity = n1 / (n2 * n2); return (vcurrent + velocity * dt).ToNormalizedQuaternion(); }