From fa53191b6ec18bc87e6c79bceed0e5ffe9fffa23 Mon Sep 17 00:00:00 2001 From: miwarnec Date: Mon, 4 Nov 2024 22:04:46 +0100 Subject: [PATCH] fix: don't apply any hybrid rpcs in host mode, fixes overwriting client's data points --- .../NetworkTransformHybrid2022.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs b/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs index ad9498fd0..ee64e27d8 100644 --- a/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs +++ b/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs @@ -338,6 +338,11 @@ void RpcServerToClientBaseline_PositionRotation(byte baselineTick, Vector3 posit // ignore if this object is owned by this client. if (IsClientWithAuthority) return; + // host mode: baseline Rpc is also sent through host's local connection and applied. + // applying host's baseline as last deserialized would overwrite the owner client's data and cause jitter. + // in other words: never apply the rpcs in host mode. + if (isServer) return; + // save last deserialized baseline tick number to compare deltas against lastDeserializedBaselineTick = baselineTick; lastDeserializedBaselinePosition = position; @@ -358,6 +363,11 @@ void RpcServerToClientBaseline_Position(byte baselineTick, Vector3 position) // ignore if this object is owned by this client. if (IsClientWithAuthority) return; + // host mode: baseline Rpc is also sent through host's local connection and applied. + // applying host's baseline as last deserialized would overwrite the owner client's data and cause jitter. + // in other words: never apply the rpcs in host mode. + if (isServer) return; + // save last deserialized baseline tick number to compare deltas against lastDeserializedBaselineTick = baselineTick; lastDeserializedBaselinePosition = position; @@ -377,6 +387,11 @@ void RpcServerToClientBaseline_Rotation(byte baselineTick, Quaternion rotation) // ignore if this object is owned by this client. if (IsClientWithAuthority) return; + // host mode: baseline Rpc is also sent through host's local connection and applied. + // applying host's baseline as last deserialized would overwrite the owner client's data and cause jitter. + // in other words: never apply the rpcs in host mode. + if (isServer) return; + // save last deserialized baseline tick number to compare deltas against lastDeserializedBaselineTick = baselineTick; lastDeserializedBaselineRotation = rotation; @@ -394,6 +409,11 @@ void RpcServerToClientDelta_PositionRotation(byte baselineTick, Vector3 position // ignore if this object is owned by this client. if (IsClientWithAuthority) return; + // host mode: baseline Rpc is also sent through host's local connection and applied. + // applying host's baseline as last deserialized would overwrite the owner client's data and cause jitter. + // in other words: never apply the rpcs in host mode. + if (isServer) return; + // debug draw: delta if (debugDraw) Debug.DrawLine(position, position + Vector3.up, Color.white, 10f); @@ -408,6 +428,11 @@ void RpcServerToClientDelta_Position(byte baselineTick, Vector3 position) // ignore if this object is owned by this client. if (IsClientWithAuthority) return; + // host mode: baseline Rpc is also sent through host's local connection and applied. + // applying host's baseline as last deserialized would overwrite the owner client's data and cause jitter. + // in other words: never apply the rpcs in host mode. + if (isServer) return; + // debug draw: delta if (debugDraw) Debug.DrawLine(position, position + Vector3.up, Color.white, 10f); @@ -422,6 +447,11 @@ void RpcServerToClientDelta_Rotation(byte baselineTick, Quaternion rotation) // ignore if this object is owned by this client. if (IsClientWithAuthority) return; + // host mode: baseline Rpc is also sent through host's local connection and applied. + // applying host's baseline as last deserialized would overwrite the owner client's data and cause jitter. + // in other words: never apply the rpcs in host mode. + if (isServer) return; + OnServerToClientDeltaSync(baselineTick, Vector3.zero, rotation);//, scale); }