Skip to content

Commit 8a109fa

Browse files
authored
chore: making NetworkTransform's interpolation bounds configurable. (#1979)
* chore: making NetworkTransform's interpolation bounds configurable. Fixes an intermittent test breakage due to extrapolation bringing us out-of-bounds * style: coding standard adjustments
1 parent a4edf18 commit 8a109fa

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

com.unity.netcode.gameobjects/Components/Interpolator/BufferedLinearInterpolator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Unity.Netcode
1010
/// </summary>
1111
public abstract class BufferedLinearInterpolator<T> where T : struct
1212
{
13+
internal float MaxInterpolationBound = 3.0f;
1314
private struct BufferedItem
1415
{
1516
public T Item;
@@ -203,10 +204,9 @@ public T Update(float deltaTime, double renderTime, double serverTime)
203204
t = 0.0f;
204205
}
205206

206-
if (t > 3.0f) // max extrapolation
207+
if (t > MaxInterpolationBound) // max extrapolation
207208
{
208209
// TODO this causes issues with teleport, investigate
209-
// todo make this configurable
210210
t = 1.0f;
211211
}
212212
}

com.unity.netcode.gameobjects/Components/NetworkTransform.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,17 @@ private void OnNetworkStateChanged(NetworkTransformState oldState, NetworkTransf
720720
}
721721
}
722722

723+
public void SetMaxInterpolationBound(float maxInterpolationBound)
724+
{
725+
m_PositionXInterpolator.MaxInterpolationBound = maxInterpolationBound;
726+
m_PositionYInterpolator.MaxInterpolationBound = maxInterpolationBound;
727+
m_PositionZInterpolator.MaxInterpolationBound = maxInterpolationBound;
728+
m_RotationInterpolator.MaxInterpolationBound = maxInterpolationBound;
729+
m_ScaleXInterpolator.MaxInterpolationBound = maxInterpolationBound;
730+
m_ScaleYInterpolator.MaxInterpolationBound = maxInterpolationBound;
731+
m_ScaleZInterpolator.MaxInterpolationBound = maxInterpolationBound;
732+
}
733+
723734
private void Awake()
724735
{
725736
// we only want to create our interpolators during Awake so that, when pooled, we do not create tons

com.unity.netcode.gameobjects/Tests/Runtime/TransformInterpolationTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ private void Update()
3333
// Move the nested object on the server
3434
if (IsMoving)
3535
{
36-
var y = Time.realtimeSinceStartup;
37-
while (y > 10.0f)
38-
{
39-
y -= 10.0f;
40-
}
36+
var y = Time.realtimeSinceStartup % 10.0f;
4137

4238
// change the space between local and global every second
4339
GetComponent<NetworkTransform>().InLocalSpace = ((int)y % 2 == 0);
@@ -119,6 +115,7 @@ public IEnumerator TransformInterpolationTest()
119115

120116
baseObject.GetComponent<TransformInterpolationObject>().IsFixed = true;
121117
spawnedObject.GetComponent<TransformInterpolationObject>().IsMoving = true;
118+
spawnedObject.GetComponent<NetworkTransform>().SetMaxInterpolationBound(1.0f);
122119

123120
const float maxPlacementError = 0.01f;
124121

@@ -131,6 +128,7 @@ public IEnumerator TransformInterpolationTest()
131128
yield return new WaitForSeconds(0.01f);
132129
}
133130

131+
m_SpawnedObjectOnClient.GetComponent<NetworkTransform>().SetMaxInterpolationBound(1.0f);
134132
m_SpawnedObjectOnClient.GetComponent<TransformInterpolationObject>().CheckPosition = true;
135133

136134
// Test that interpolation works correctly for 10 seconds

0 commit comments

Comments
 (0)