From 7a682acaf842328b345279f13ebac7fabe3cd0f8 Mon Sep 17 00:00:00 2001 From: mischa Date: Mon, 29 Apr 2024 21:45:02 +0800 Subject: [PATCH] target blending estimate instead of interp --- .../ForecastRigidbody/ForecastRigidbody.cs | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs b/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs index 79937e6ea..172c6f8f7 100644 --- a/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs +++ b/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs @@ -296,11 +296,28 @@ protected override void ApplySnapshot(NTSnapshot interpolated) // blend between local position and server snapshots else if (state == ForecastState.BLENDING) { - // DEBUG: force FOLLOW for now - // snapshot interpolation: get the interpolated remote position at this time. - // if there is no snapshot yet, just use lastReceived - Vector3 targetPosition = interpolated.position; - Quaternion targetRotation = interpolated.rotation; + // first principles: + // + // BLENDING needs to interpolate between PREDICTING & FOLLOWING. + // the only way to do this without jitter and jumps is by + // interpolating from BLENDING.startPosition to BLENDING.endPosition. + // anything else, no matter how smooth, will always cause jumps. + // + // BLENDING.startPosition is easy: just remember before transition. + // + // BLENDING.endPosition is a bit harder. + // => we can sample snapshots @ blendingEndTime (if any). + // => if we haven't received it yet, we need to extrpolate based + // on current velocity to guess where we'll be at blendingEndTime. + + // do we have an estimate yet? + if (!blendingEndPositionEstimate.HasValue) + { + // Debug.Log("Blending: waiting for estimate..."); + return; + } + Vector3 targetPosition = blendingEndPositionEstimate.Value; + Quaternion targetRotation = blendingEndRotationEstimate.Value; // blend between local and remote position // set debug color