public void ProcessAnimation(AnimationStream stream) { float w = jobWeight.Get(stream); float streamDt = Mathf.Abs(stream.deltaTime); driven.GetGlobalTR(stream, out Vector3 drivenPos, out Quaternion drivenRot); if (w > 0f && streamDt > 0f) { source.GetGlobalTR(stream, out Vector3 sourcePos, out Quaternion sourceRot); var sourceTx = new AffineTransform(sourcePos, sourceRot); var targetTx = sourceTx * localBindTx; targetTx.translation = Vector3.Lerp(drivenPos, targetTx.translation, w); targetTx.rotation = Quaternion.Lerp(drivenRot, targetTx.rotation, w); var dampPosW = AnimationRuntimeUtils.Square(1f - dampPosition.Get(stream)); var dampRotW = AnimationRuntimeUtils.Square(1f - dampRotation.Get(stream)); bool doAimAjustements = Vector3.Dot(aimBindAxis, aimBindAxis) > 0f; while (streamDt > 0f) { float factoredDt = k_DampFactor * Mathf.Min(k_FixedDt, streamDt); prevDrivenTx.translation += (targetTx.translation - prevDrivenTx.translation) * dampPosW * factoredDt; prevDrivenTx.rotation *= Quaternion.Lerp( Quaternion.identity, Quaternion.Inverse(prevDrivenTx.rotation) * targetTx.rotation, dampRotW * factoredDt ); if (doAimAjustements) { var fromDir = prevDrivenTx.rotation * aimBindAxis; var toDir = sourceTx.translation - prevDrivenTx.translation; prevDrivenTx.rotation = Quaternion.AngleAxis(Vector3.Angle(fromDir, toDir), Vector3.Cross(fromDir, toDir).normalized) * prevDrivenTx.rotation; } streamDt -= k_FixedDt; } driven.SetGlobalTR(stream, prevDrivenTx.translation, prevDrivenTx.rotation); } else { prevDrivenTx.Set(drivenPos, drivenRot); AnimationRuntimeUtils.PassThrough(stream, driven); } }