Skip to content

chore: making NetworkTransform's interpolation bounds configurable. #1979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Unity.Netcode
/// </summary>
public abstract class BufferedLinearInterpolator<T> where T : struct
{
internal float MaxInterpolationBound = 3.0f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seconds? milliseconds? years? :)

private struct BufferedItem
{
public T Item;
Expand Down Expand Up @@ -203,10 +204,9 @@ public T Update(float deltaTime, double renderTime, double serverTime)
t = 0.0f;
}

if (t > 3.0f) // max extrapolation
if (t > MaxInterpolationBound) // max extrapolation
{
// TODO this causes issues with teleport, investigate
// todo make this configurable
t = 1.0f;
}
}
Expand Down
11 changes: 11 additions & 0 deletions com.unity.netcode.gameobjects/Components/NetworkTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,17 @@ private void OnNetworkStateChanged(NetworkTransformState oldState, NetworkTransf
}
}

public void SetMaxInterpolationBound(float maxInterpolationBound)
{
m_PositionXInterpolator.MaxInterpolationBound = maxInterpolationBound;
m_PositionYInterpolator.MaxInterpolationBound = maxInterpolationBound;
m_PositionZInterpolator.MaxInterpolationBound = maxInterpolationBound;
m_RotationInterpolator.MaxInterpolationBound = maxInterpolationBound;
m_ScaleXInterpolator.MaxInterpolationBound = maxInterpolationBound;
m_ScaleYInterpolator.MaxInterpolationBound = maxInterpolationBound;
m_ScaleZInterpolator.MaxInterpolationBound = maxInterpolationBound;
}

private void Awake()
{
// we only want to create our interpolators during Awake so that, when pooled, we do not create tons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ private void Update()
// Move the nested object on the server
if (IsMoving)
{
var y = Time.realtimeSinceStartup;
while (y > 10.0f)
{
y -= 10.0f;
}
var y = Time.realtimeSinceStartup % 10.0f;

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

baseObject.GetComponent<TransformInterpolationObject>().IsFixed = true;
spawnedObject.GetComponent<TransformInterpolationObject>().IsMoving = true;
spawnedObject.GetComponent<NetworkTransform>().SetMaxInterpolationBound(1.0f);

const float maxPlacementError = 0.01f;

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

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

// Test that interpolation works correctly for 10 seconds
Expand Down