From 27eaf67a5a4fe5e0a407c7c5d02d55df2b3ac35a Mon Sep 17 00:00:00 2001 From: vis2k Date: Sat, 18 Mar 2023 10:50:38 +0800 Subject: [PATCH] fix: #3427 NetworKTransformReliable now has a timelineOffset to account for decoupled arrival of NetworkTime and NetworkTransform snapshots --- .../NetworkTransformReliable.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Components/NetworkTransformReliable/NetworkTransformReliable.cs b/Assets/Mirror/Components/NetworkTransformReliable/NetworkTransformReliable.cs index 435d87a14..b3aa13858 100644 --- a/Assets/Mirror/Components/NetworkTransformReliable/NetworkTransformReliable.cs +++ b/Assets/Mirror/Components/NetworkTransformReliable/NetworkTransformReliable.cs @@ -33,6 +33,10 @@ public class NetworkTransformReliable : NetworkTransformBase [Range(0.00_01f, 1f)] // disallow 0 division. 1mm to 1m precision is enough range. public float scalePrecision = 0.01f; // 1 cm + [Header("Snapshot Interpolation")] + [Tooltip("Add a small timeline offset to account for decoupled arrival of NetworkTime and NetworkTransform snapshots.\nfixes: https://github.com/MirrorNetworking/Mirror/issues/3427")] + public float timelineOffset = 0; + // delta compression needs to remember 'last' to compress against protected Vector3Long lastSerializedPosition = Vector3Long.zero; protected Vector3Long lastDeserializedPosition = Vector3Long.zero; @@ -298,7 +302,11 @@ protected virtual void OnClientToServerSync(Vector3? position, Quaternion? rotat // Debug.Log($"{name}: corrected history on server to fix initial stutter after not sending for a while."); } - AddSnapshot(serverSnapshots, connectionToClient.remoteTimeStamp, position, rotation, scale); + // add a small timeline offset to account for decoupled arrival of + // NetworkTime and NetworkTransform snapshots. + // fixes: https://github.com/MirrorNetworking/Mirror/issues/3427 + // remove this after LocalWorldState. + AddSnapshot(serverSnapshots, connectionToClient.remoteTimeStamp + timelineOffset, position, rotation, scale); } // server broadcasts sync message to all clients @@ -322,7 +330,11 @@ protected virtual void OnServerToClientSync(Vector3? position, Quaternion? rotat // Debug.Log($"{name}: corrected history on client to fix initial stutter after not sending for a while."); } - AddSnapshot(clientSnapshots, NetworkClient.connection.remoteTimeStamp, position, rotation, scale); + // add a small timeline offset to account for decoupled arrival of + // NetworkTime and NetworkTransform snapshots. + // fixes: https://github.com/MirrorNetworking/Mirror/issues/3427 + // remove this after LocalWorldState. + AddSnapshot(clientSnapshots, NetworkClient.connection.remoteTimeStamp + timelineOffset, position, rotation, scale); } // only sync on change /////////////////////////////////////////////////