File tree Expand file tree Collapse file tree 4 files changed +20
-0
lines changed
com.unity.netcode.gameobjects Expand file tree Collapse file tree 4 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public class NetworkRigidbody : NetworkBehaviour
1414 private NetworkTransform m_NetworkTransform ;
1515
1616 private bool m_OriginalKinematic ;
17+ private RigidbodyInterpolation m_OriginalInterpolation ;
1718
1819 // Used to cache the authority state of this rigidbody during the last frame
1920 private bool m_IsAuthority ;
@@ -48,11 +49,16 @@ private void UpdateRigidbodyKinematicMode()
4849 {
4950 m_OriginalKinematic = m_Rigidbody . isKinematic ;
5051 m_Rigidbody . isKinematic = true ;
52+
53+ m_OriginalInterpolation = m_Rigidbody . interpolation ;
54+ // Set interpolation to none, the NetworkTransform component interpolates the position of the object.
55+ m_Rigidbody . interpolation = RigidbodyInterpolation . None ;
5156 }
5257 else
5358 {
5459 // Resets the rigidbody back to it's non replication only state. Happens on shutdown and when authority is lost
5560 m_Rigidbody . isKinematic = m_OriginalKinematic ;
61+ m_Rigidbody . interpolation = m_OriginalInterpolation ;
5662 }
5763 }
5864
@@ -61,6 +67,7 @@ public override void OnNetworkSpawn()
6167 {
6268 m_IsAuthority = HasAuthority ;
6369 m_OriginalKinematic = m_Rigidbody . isKinematic ;
70+ m_OriginalInterpolation = m_Rigidbody . interpolation ;
6471 UpdateRigidbodyKinematicMode ( ) ;
6572 }
6673
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public class NetworkRigidbody2D : NetworkBehaviour
1414 private NetworkTransform m_NetworkTransform ;
1515
1616 private bool m_OriginalKinematic ;
17+ private RigidbodyInterpolation2D m_OriginalInterpolation ;
1718
1819 // Used to cache the authority state of this rigidbody during the last frame
1920 private bool m_IsAuthority ;
@@ -48,11 +49,16 @@ private void UpdateRigidbodyKinematicMode()
4849 {
4950 m_OriginalKinematic = m_Rigidbody . isKinematic ;
5051 m_Rigidbody . isKinematic = true ;
52+
53+ m_OriginalInterpolation = m_Rigidbody . interpolation ;
54+ // Set interpolation to none, the NetworkTransform component interpolates the position of the object.
55+ m_Rigidbody . interpolation = RigidbodyInterpolation2D . None ;
5156 }
5257 else
5358 {
5459 // Resets the rigidbody back to it's non replication only state. Happens on shutdown and when authority is lost
5560 m_Rigidbody . isKinematic = m_OriginalKinematic ;
61+ m_Rigidbody . interpolation = m_OriginalInterpolation ;
5662 }
5763 }
5864
@@ -61,6 +67,7 @@ public override void OnNetworkSpawn()
6167 {
6268 m_IsAuthority = HasAuthority ;
6369 m_OriginalKinematic = m_Rigidbody . isKinematic ;
70+ m_OriginalInterpolation = m_Rigidbody . interpolation ;
6471 UpdateRigidbodyKinematicMode ( ) ;
6572 }
6673
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public override IEnumerator Setup()
3030 playerPrefab . AddComponent < NetworkTransform > ( ) ;
3131 playerPrefab . AddComponent < Rigidbody2D > ( ) ;
3232 playerPrefab . AddComponent < NetworkRigidbody2D > ( ) ;
33+ playerPrefab . GetComponent < Rigidbody2D > ( ) . interpolation = RigidbodyInterpolation2D . Interpolate ;
3334 playerPrefab . GetComponent < Rigidbody2D > ( ) . isKinematic = Kinematic ;
3435 } ) ;
3536 }
@@ -58,9 +59,11 @@ public IEnumerator TestRigidbodyKinematicEnableDisable()
5859
5960 // server rigidbody has authority and should have a kinematic mode of false
6061 Assert . True ( serverPlayer . GetComponent < Rigidbody2D > ( ) . isKinematic == Kinematic ) ;
62+ Assert . AreEqual ( RigidbodyInterpolation2D . Interpolate , serverPlayer . GetComponent < Rigidbody2D > ( ) . interpolation ) ;
6163
6264 // client rigidbody has no authority and should have a kinematic mode of true
6365 Assert . True ( clientPlayer . GetComponent < Rigidbody2D > ( ) . isKinematic ) ;
66+ Assert . AreEqual ( RigidbodyInterpolation2D . None , clientPlayer . GetComponent < Rigidbody2D > ( ) . interpolation ) ;
6467
6568 // despawn the server player, (but keep it around on the server)
6669 serverPlayer . GetComponent < NetworkObject > ( ) . Despawn ( false ) ;
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public override IEnumerator Setup()
3030 playerPrefab . AddComponent < NetworkTransform > ( ) ;
3131 playerPrefab . AddComponent < Rigidbody > ( ) ;
3232 playerPrefab . AddComponent < NetworkRigidbody > ( ) ;
33+ playerPrefab . GetComponent < Rigidbody > ( ) . interpolation = RigidbodyInterpolation . Interpolate ;
3334 playerPrefab . GetComponent < Rigidbody > ( ) . isKinematic = Kinematic ;
3435 } ) ;
3536 }
@@ -58,9 +59,11 @@ public IEnumerator TestRigidbodyKinematicEnableDisable()
5859
5960 // server rigidbody has authority and should have a kinematic mode of false
6061 Assert . True ( serverPlayer . GetComponent < Rigidbody > ( ) . isKinematic == Kinematic ) ;
62+ Assert . AreEqual ( RigidbodyInterpolation . Interpolate , serverPlayer . GetComponent < Rigidbody > ( ) . interpolation ) ;
6163
6264 // client rigidbody has no authority and should have a kinematic mode of true
6365 Assert . True ( clientPlayer . GetComponent < Rigidbody > ( ) . isKinematic ) ;
66+ Assert . AreEqual ( RigidbodyInterpolation . None , clientPlayer . GetComponent < Rigidbody > ( ) . interpolation ) ;
6467
6568 // despawn the server player (but keep it around on the server)
6669 serverPlayer . GetComponent < NetworkObject > ( ) . Despawn ( false ) ;
You can’t perform that action at this time.
0 commit comments