Skip to content

Commit 57e2b36

Browse files
fix
Removing unclamped slerp and lerp due to a few timing related issues. These issues should be solved before re-enabling any form of unclamped lerping/slerping with BufferedLinearInterpolator. Added additional comments in some areas to be investigated for a potential fix.
1 parent e73b88a commit 57e2b36

File tree

2 files changed

+22
-42
lines changed

2 files changed

+22
-42
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ public void AddMeasurement(T newMeasurement, double sentTime)
248248
return;
249249
}
250250

251+
// Part the of reason for disabling extrapolation is how we add and use measurements over time.
252+
// TODO: Add detailed description of this area in Jira ticket
251253
if (sentTime > m_EndTimeConsumed || m_LifetimeConsumedCount == 0) // treat only if value is newer than the one being interpolated to right now
252254
{
253255
m_LastBufferedItemReceived = new BufferedItem(newMeasurement, sentTime);
@@ -292,7 +294,9 @@ public class BufferedLinearInterpolatorFloat : BufferedLinearInterpolator<float>
292294
/// <inheritdoc />
293295
protected override float InterpolateUnclamped(float start, float end, float time)
294296
{
295-
return Mathf.LerpUnclamped(start, end, time);
297+
// Disabling Extrapolation:
298+
// TODO: Add Jira Ticket
299+
return Mathf.Lerp(start, end, time);
296300
}
297301

298302
/// <inheritdoc />
@@ -311,13 +315,17 @@ public class BufferedLinearInterpolatorQuaternion : BufferedLinearInterpolator<Q
311315
/// <inheritdoc />
312316
protected override Quaternion InterpolateUnclamped(Quaternion start, Quaternion end, float time)
313317
{
314-
return Quaternion.SlerpUnclamped(start, end, time);
318+
// Disabling Extrapolation:
319+
// TODO: Add Jira Ticket
320+
return Quaternion.Slerp(start, end, time);
315321
}
316322

317323
/// <inheritdoc />
318324
protected override Quaternion Interpolate(Quaternion start, Quaternion end, float time)
319325
{
320-
return Quaternion.SlerpUnclamped(start, end, time);
326+
// Disabling Extrapolation:
327+
// TODO: Add Jira Ticket
328+
return Quaternion.Slerp(start, end, time);
321329
}
322330
}
323331
}

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

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,6 @@ internal NetworkVariable<NetworkTransformState> ReplicatedNetworkState
453453
// Used by integration test
454454
private NetworkTransformState m_LastSentState;
455455

456-
// Used by the non-authoritative side to handle ending extrapolation
457-
private NetworkTransformState m_LastReceivedState;
458-
459456
internal NetworkTransformState GetLastSentState()
460457
{
461458
return m_LastSentState;
@@ -556,6 +553,8 @@ private void ResetInterpolatedStateToCurrentAuthoritativeState()
556553

557554
m_RotationInterpolator.ResetTo(transform.rotation, serverTime);
558555

556+
// TODO: (Create Jira Ticket) Synchronize local scale during NetworkObject synchronization
557+
// (We will probably want to byte pack TransformData to offset the 3 float addition)
559558
m_ScaleXInterpolator.ResetTo(transform.localScale.x, serverTime);
560559
m_ScaleYInterpolator.ResetTo(transform.localScale.y, serverTime);
561560
m_ScaleZInterpolator.ResetTo(transform.localScale.z, serverTime);
@@ -938,26 +937,6 @@ private void AddInterpolatedState(NetworkTransformState newState)
938937
}
939938
}
940939

941-
/// <summary>
942-
/// Stops extrapolating the <see cref="m_LastReceivedState"/>.
943-
/// </summary>
944-
/// <remarks>
945-
/// <see cref="OnNetworkStateChanged"/>
946-
/// </remarks>
947-
private void TryToStopExtrapolatingLastState()
948-
{
949-
if (!m_LastReceivedState.IsDirty || m_LastReceivedState.EndExtrapolationTick >= NetworkManager.LocalTime.Tick)
950-
{
951-
return;
952-
}
953-
// Offset by 1 tick duration
954-
m_LastReceivedState.SentTime += m_TickFrequency;
955-
AddInterpolatedState(m_LastReceivedState);
956-
957-
// Now reset our last received state so we won't apply this state again
958-
m_LastReceivedState.ClearBitSetForNextTick();
959-
}
960-
961940
/// <summary>
962941
/// Only non-authoritative instances should invoke this method
963942
/// </summary>
@@ -976,21 +955,8 @@ private void OnNetworkStateChanged(NetworkTransformState oldState, NetworkTransf
976955

977956
if (Interpolate)
978957
{
979-
// This is "just in case" we receive a new state before the end
980-
// of any currently applied and potentially extrapolating state.
981-
// Attempts to stop extrapolating any previously applied state.
982-
TryToStopExtrapolatingLastState();
983-
984958
// Add measurements for the new state's deltas
985959
AddInterpolatedState(newState);
986-
987-
// Set the last received state to the new state (will be used to stop extrapolating the new state on the next local tick)
988-
m_LastReceivedState = newState;
989-
990-
// Set the current local tick and wait until the next tick before we end
991-
// this state's potential of extrapolating past the target value beyond
992-
// the state's relative tick duration
993-
m_LastReceivedState.EndExtrapolationTick = NetworkManager.LocalTime.Tick;
994960
}
995961
}
996962

@@ -1115,6 +1081,11 @@ private void Initialize()
11151081
// In case we are late joining
11161082
ResetInterpolatedStateToCurrentAuthoritativeState();
11171083
}
1084+
1085+
if (!IsServer)
1086+
{
1087+
Interpolate = false;
1088+
}
11181089
}
11191090

11201091
/// <summary>
@@ -1261,6 +1232,10 @@ protected virtual void Update()
12611232
{
12621233
return;
12631234
}
1235+
if (!IsServer)
1236+
{
1237+
Interpolate = false;
1238+
}
12641239

12651240
// If we are authority, update the authoritative state
12661241
if (CanCommitToTransform)
@@ -1285,9 +1260,6 @@ protected virtual void Update()
12851260

12861261
// Apply the current authoritative state
12871262
ApplyAuthoritativeState();
1288-
1289-
// Attempts to stop extrapolating any previously applied state.
1290-
TryToStopExtrapolatingLastState();
12911263
}
12921264
}
12931265

0 commit comments

Comments
 (0)