From 30d7b5b3a89a51c7ed4507b53a2b9975d376b767 Mon Sep 17 00:00:00 2001 From: mischa <16416509+vis2k@users.noreply.github.com> Date: Mon, 20 Mar 2023 03:36:21 +0100 Subject: [PATCH] fix: #3427 NetworKTransformReliable now has a timelineOffset to account for decoupled arrival of NetworkTime and NetworkTransform snapshots (#3428) * fix: #3427 NetworKTransformReliable now has a timelineOffset to account for decoupled arrival of NetworkTime and NetworkTransform snapshots * bool --- .../NetworkTransformReliable.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Components/NetworkTransformReliable/NetworkTransformReliable.cs b/Assets/Mirror/Components/NetworkTransformReliable/NetworkTransformReliable.cs index 435d87a14..28d50c1ea 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 bool timelineOffset = false; + // delta compression needs to remember 'last' to compress against protected Vector3Long lastSerializedPosition = Vector3Long.zero; protected Vector3Long lastDeserializedPosition = Vector3Long.zero; @@ -298,7 +302,13 @@ 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. + // needs to be sendInterval. half sendInterval doesn't solve it. + // https://github.com/MirrorNetworking/Mirror/issues/3427 + // remove this after LocalWorldState. + double offset = timelineOffset ? NetworkServer.sendInterval : 0; + AddSnapshot(serverSnapshots, connectionToClient.remoteTimeStamp + offset, position, rotation, scale); } // server broadcasts sync message to all clients @@ -322,7 +332,13 @@ 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. + // needs to be sendInterval. half sendInterval doesn't solve it. + // https://github.com/MirrorNetworking/Mirror/issues/3427 + // remove this after LocalWorldState. + double offset = timelineOffset ? NetworkServer.sendInterval : 0; + AddSnapshot(clientSnapshots, NetworkClient.connection.remoteTimeStamp + offset, position, rotation, scale); } // only sync on change /////////////////////////////////////////////////