From 07115f0159a128e1a4672126d3bd446d3b3de59f Mon Sep 17 00:00:00 2001 From: Pino De Francesco Date: Tue, 30 Jul 2024 15:12:56 +0100 Subject: [PATCH] fix: abide by the original RigidBody2D body type fix: the 1.10 imposed Dynamic body type even when the user set it originally as Kinematic Implemented a check that changes the body type to Dynamic when there is ownership only if originally it was instantiated as Dynamic, otherwise, it keeps it Kinematic. This to avoid overriding what the user had originally designed. --- .../Components/NetworkRigidbody2D.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs b/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs index 4d7d4b153c..b2a70adc15 100644 --- a/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs +++ b/com.unity.netcode.gameobjects/Components/NetworkRigidbody2D.cs @@ -17,6 +17,13 @@ public class NetworkRigidbody2D : NetworkBehaviour /// private bool m_IsServerAuthoritative; + /// + /// Stores the original body type of the rigidbody + /// so to abide to the original type desired by the user + /// when authority changes + /// + private RigidbodyType2D m_OriginalBodyType; + private Rigidbody2D m_Rigidbody; private NetworkTransform m_NetworkTransform; @@ -48,11 +55,14 @@ private void SetupRigidBody() m_Rigidbody = GetComponent(); m_OriginalInterpolation = m_Rigidbody.interpolation; + // Store the original body type of the rigidbody + m_OriginalBodyType = m_Rigidbody.bodyType; + m_Rigidbody.interpolation = m_IsAuthority ? m_OriginalInterpolation : (m_NetworkTransform.Interpolate ? RigidbodyInterpolation2D.None : m_OriginalInterpolation); // Turn off physics for the rigid body until spawned, otherwise // clients can run fixed update before the first full // NetworkTransform update - m_Rigidbody.isKinematic = true; + m_Rigidbody.bodyType = RigidbodyType2D.Kinematic; } /// @@ -89,7 +99,8 @@ private void UpdateOwnershipAuthority() } // If you have authority then you are not kinematic - m_Rigidbody.isKinematic = !m_IsAuthority; + // unless the original body type was set to be Kinematic by the user + m_Rigidbody.bodyType = m_IsAuthority && m_OriginalBodyType == RigidbodyType2D.Dynamic ? RigidbodyType2D.Dynamic : RigidbodyType2D.Kinematic; // Set interpolation of the Rigidbody2D based on authority // With authority: let local transform handle interpolation