target blending estimate instead of interp

This commit is contained in:
mischa 2024-04-29 21:45:02 +08:00
parent af233ba256
commit 7a682acaf8

View File

@ -296,11 +296,28 @@ protected override void ApplySnapshot(NTSnapshot interpolated)
// blend between local position and server snapshots // blend between local position and server snapshots
else if (state == ForecastState.BLENDING) else if (state == ForecastState.BLENDING)
{ {
// DEBUG: force FOLLOW for now // first principles:
// snapshot interpolation: get the interpolated remote position at this time. //
// if there is no snapshot yet, just use lastReceived // BLENDING needs to interpolate between PREDICTING & FOLLOWING.
Vector3 targetPosition = interpolated.position; // the only way to do this without jitter and jumps is by
Quaternion targetRotation = interpolated.rotation; // 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 // blend between local and remote position
// set debug color // set debug color