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
14
14
private NetworkTransform m_NetworkTransform ;
15
15
16
16
private bool m_OriginalKinematic ;
17
+ private RigidbodyInterpolation m_OriginalInterpolation ;
17
18
18
19
// Used to cache the authority state of this rigidbody during the last frame
19
20
private bool m_IsAuthority ;
@@ -48,11 +49,16 @@ private void UpdateRigidbodyKinematicMode()
48
49
{
49
50
m_OriginalKinematic = m_Rigidbody . isKinematic ;
50
51
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 ;
51
56
}
52
57
else
53
58
{
54
59
// Resets the rigidbody back to it's non replication only state. Happens on shutdown and when authority is lost
55
60
m_Rigidbody . isKinematic = m_OriginalKinematic ;
61
+ m_Rigidbody . interpolation = m_OriginalInterpolation ;
56
62
}
57
63
}
58
64
@@ -61,6 +67,7 @@ public override void OnNetworkSpawn()
61
67
{
62
68
m_IsAuthority = HasAuthority ;
63
69
m_OriginalKinematic = m_Rigidbody . isKinematic ;
70
+ m_OriginalInterpolation = m_Rigidbody . interpolation ;
64
71
UpdateRigidbodyKinematicMode ( ) ;
65
72
}
66
73
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public class NetworkRigidbody2D : NetworkBehaviour
14
14
private NetworkTransform m_NetworkTransform ;
15
15
16
16
private bool m_OriginalKinematic ;
17
+ private RigidbodyInterpolation2D m_OriginalInterpolation ;
17
18
18
19
// Used to cache the authority state of this rigidbody during the last frame
19
20
private bool m_IsAuthority ;
@@ -48,11 +49,16 @@ private void UpdateRigidbodyKinematicMode()
48
49
{
49
50
m_OriginalKinematic = m_Rigidbody . isKinematic ;
50
51
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 ;
51
56
}
52
57
else
53
58
{
54
59
// Resets the rigidbody back to it's non replication only state. Happens on shutdown and when authority is lost
55
60
m_Rigidbody . isKinematic = m_OriginalKinematic ;
61
+ m_Rigidbody . interpolation = m_OriginalInterpolation ;
56
62
}
57
63
}
58
64
@@ -61,6 +67,7 @@ public override void OnNetworkSpawn()
61
67
{
62
68
m_IsAuthority = HasAuthority ;
63
69
m_OriginalKinematic = m_Rigidbody . isKinematic ;
70
+ m_OriginalInterpolation = m_Rigidbody . interpolation ;
64
71
UpdateRigidbodyKinematicMode ( ) ;
65
72
}
66
73
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public override IEnumerator Setup()
30
30
playerPrefab . AddComponent < NetworkTransform > ( ) ;
31
31
playerPrefab . AddComponent < Rigidbody2D > ( ) ;
32
32
playerPrefab . AddComponent < NetworkRigidbody2D > ( ) ;
33
+ playerPrefab . GetComponent < Rigidbody2D > ( ) . interpolation = RigidbodyInterpolation2D . Interpolate ;
33
34
playerPrefab . GetComponent < Rigidbody2D > ( ) . isKinematic = Kinematic ;
34
35
} ) ;
35
36
}
@@ -58,9 +59,11 @@ public IEnumerator TestRigidbodyKinematicEnableDisable()
58
59
59
60
// server rigidbody has authority and should have a kinematic mode of false
60
61
Assert . True ( serverPlayer . GetComponent < Rigidbody2D > ( ) . isKinematic == Kinematic ) ;
62
+ Assert . AreEqual ( RigidbodyInterpolation2D . Interpolate , serverPlayer . GetComponent < Rigidbody2D > ( ) . interpolation ) ;
61
63
62
64
// client rigidbody has no authority and should have a kinematic mode of true
63
65
Assert . True ( clientPlayer . GetComponent < Rigidbody2D > ( ) . isKinematic ) ;
66
+ Assert . AreEqual ( RigidbodyInterpolation2D . None , clientPlayer . GetComponent < Rigidbody2D > ( ) . interpolation ) ;
64
67
65
68
// despawn the server player, (but keep it around on the server)
66
69
serverPlayer . GetComponent < NetworkObject > ( ) . Despawn ( false ) ;
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public override IEnumerator Setup()
30
30
playerPrefab . AddComponent < NetworkTransform > ( ) ;
31
31
playerPrefab . AddComponent < Rigidbody > ( ) ;
32
32
playerPrefab . AddComponent < NetworkRigidbody > ( ) ;
33
+ playerPrefab . GetComponent < Rigidbody > ( ) . interpolation = RigidbodyInterpolation . Interpolate ;
33
34
playerPrefab . GetComponent < Rigidbody > ( ) . isKinematic = Kinematic ;
34
35
} ) ;
35
36
}
@@ -58,9 +59,11 @@ public IEnumerator TestRigidbodyKinematicEnableDisable()
58
59
59
60
// server rigidbody has authority and should have a kinematic mode of false
60
61
Assert . True ( serverPlayer . GetComponent < Rigidbody > ( ) . isKinematic == Kinematic ) ;
62
+ Assert . AreEqual ( RigidbodyInterpolation . Interpolate , serverPlayer . GetComponent < Rigidbody > ( ) . interpolation ) ;
61
63
62
64
// client rigidbody has no authority and should have a kinematic mode of true
63
65
Assert . True ( clientPlayer . GetComponent < Rigidbody > ( ) . isKinematic ) ;
66
+ Assert . AreEqual ( RigidbodyInterpolation . None , clientPlayer . GetComponent < Rigidbody > ( ) . interpolation ) ;
64
67
65
68
// despawn the server player (but keep it around on the server)
66
69
serverPlayer . GetComponent < NetworkObject > ( ) . Despawn ( false ) ;
You can’t perform that action at this time.
0 commit comments