Skip to content

Commit cad4b4c

Browse files
fix: buffered linear interpolator jitter and exposing more properties (#3355)
After doing some testing I noticed a few anomalies with the updated `BufferedLinearInterpolator<T>`. As it turns out, there are more than one approaches a user might need depending upon what they are trying to accomplish and each option really performs best when tweaking some properties within the `BufferedLinearInterpolator<T>` that were not completely exposed. ### Various options: - You might want to enable, disable, or adjust the maximum interpolation time of the last smooth lerp phase for each interpolator type. - You might want to manually adjust the tick latency offset (`NetworkTransform.InterpolationBufferTickOffset`) used depending upon context. - When using a client-server topology, you might want this to be set to something like 0 or 1 (depending upon interpolator). - You might want this value to be higher (like say +2-3 depending on latency and interpolation type) on non-authority instances where the authority is some other client and not the host/server. ### This PR renames `Lerp` to `LegacyLerp` and adds a 3rd new `Lerp` interpolator type: #### Lerp (new) Uses a 1 to 2 phase approach that lerps towards the target, lerps towards the next target (if one exists) ahead by 1 frame delta, blends the two results, and (optionally) smooth the final value. - The first phase lerps towards the current tick state update being processed. - The fourth phase (optional) performs a lerp smoothing where the current respective transform value is lerped towards the result of the first phase at a rate of 1.0f minus the max interpolation time. ## Changelog - Added: `Lerp` interpolation type that still uses a lerp approach but uses the new buffer consumption logic. - Added: Property to enable or disable lerp smoothing for position, rotation, and scale interpolators. - Added: `NetworkTransform.InterpolationBufferTickOffset` static property to provide users with a way to increase or decrease the time marker where interpolators will pull state update from the queue. - Fixed: Issue where the time delta that interpolators used would not be properly updated during multiple fixed update invocations within the same player loop frame. - Changed: The original `Lerp` to be renamed to `LegacyLerp`. ## Testing and Documentation - Includes integration test updates. - Includes documentation for public API entry points. - Includes updates to public documentation for `NetworkTransform`. (Will be adding to [PR-1443](Unity-Technologies/com.unity.multiplayer.docs#1443)) <!-- Uncomment and mark items off with a * if this PR deprecates any API: ### Deprecated API - [ ] An `[Obsolete]` attribute was added along with a `(RemovedAfter yyyy-mm-dd)` entry. - [ ] An [api updater] was added. - [ ] Deprecation of the API is explained in the CHANGELOG. - [ ] The users can understand why this API was removed and what they should use instead. --> --------- Co-authored-by: Emma <[email protected]>
1 parent 0e1ae7e commit cad4b4c

16 files changed

+910
-325
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Additional documentation and release notes are available at [Multiplayer Documen
1111
### Added
1212

1313
- Added `NetworkManager.OnPreShutdown` which is called before the NetworkManager cleans up and shuts down. (#3366)
14+
- Added `Lerp` interpolation type that still uses a lerp approach but uses the new buffer consumption logic. (#3355)
15+
- Added property to enable or disable lerp smoothing for position, rotation, and scale interpolators. (#3355)
16+
- Added `NetworkTransform.InterpolationBufferTickOffset` static property to provide users with a way to increase or decrease the time marker where interpolators will pull state update from the queue. (#3355)
1417
- Added interpolator types as an inspector view selection for position, rotation, and scale. (#3337)
1518
- Added a new smooth dampening interpolator type that provides a nice balance between precision and smoothing results. (#3337)
1619
- Added `NetworkTimeSystem.TickLatency` property that provides the average latency of a client. (#3337)
@@ -19,6 +22,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1922

2023
### Fixed
2124

25+
- Fixed issue where the time delta that interpolators used would not be properly updated during multiple fixed update invocations within the same player loop frame. (#3355)
2226
- Fixed issue when using a distributed authority network topology and many clients attempt to connect simultaneously the session owner could max-out the maximum in-flight reliable messages allowed, start dropping packets, and some of the connecting clients would fail to fully synchronize. (#3350)
2327
- Fixed issue when using a distributed authority network topology and scene management was disabled clients would not be able to spawn any new network prefab instances until synchronization was complete. (#3350)
2428
- Fixed issue where an owner that changes ownership, when using a distributed authority network topology, could yield identical previous and current owner identifiers. This could also cause `NetworkTransform` to fail to change ownership which would leave the previous owner still subscribed to network tick events. (#3347)
@@ -39,8 +43,9 @@ Additional documentation and release notes are available at [Multiplayer Documen
3943

4044
### Changed
4145

46+
- Changed the original `Lerp` interpolation type to `LegacyLerp`. (#3355)
4247
- Changed `BufferedLinearInterpolator<T>.Update(float deltaTime, NetworkTime serverTime)` as being deprecated since this method is only used for internal testing purposes. (#3337)
43-
- Ensured that a useful error is thrown when attempting to build a dedicated server with Unity Transport that uses websockets. (#3336)
48+
- Changed error thrown when attempting to build a dedicated server with Unity Transport that uses websockets to provide more useful information to the user. (#3336)
4449
- Changed root in-scene placed `NetworkObject` instances now will always have either the `Distributable` permission set unless the `SessionOwner` permission is set. (#3305)
4550
- Changed the `DestroyObject` message to reduce the serialized message size and remove the unnecessary message field. (#3304)
4651
- Changed the `NetworkTimeSystem.Sync` method to use half RTT to calculate the desired local time offset as opposed to the full RTT. (#3212)

com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs

+26-12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class NetworkTransformEditor : NetcodeEditorBase<NetworkTransform>
3131
private SerializedProperty m_PositionInterpolationTypeProperty;
3232
private SerializedProperty m_RotationInterpolationTypeProperty;
3333
private SerializedProperty m_ScaleInterpolationTypeProperty;
34+
private SerializedProperty m_PositionLerpSmoothing;
35+
private SerializedProperty m_RotationLerpSmoothing;
36+
private SerializedProperty m_ScaleLerpSmoothing;
3437

3538
private SerializedProperty m_PositionMaximumInterpolationTimeProperty;
3639
private SerializedProperty m_RotationMaximumInterpolationTimeProperty;
@@ -77,6 +80,11 @@ public override void OnEnable()
7780
m_ScaleInterpolationTypeProperty = serializedObject.FindProperty(nameof(NetworkTransform.ScaleInterpolationType));
7881
m_ScaleMaximumInterpolationTimeProperty = serializedObject.FindProperty(nameof(NetworkTransform.ScaleMaxInterpolationTime));
7982

83+
m_PositionLerpSmoothing = serializedObject.FindProperty(nameof(NetworkTransform.PositionLerpSmoothing));
84+
m_RotationLerpSmoothing = serializedObject.FindProperty(nameof(NetworkTransform.RotationLerpSmoothing));
85+
m_ScaleLerpSmoothing = serializedObject.FindProperty(nameof(NetworkTransform.ScaleLerpSmoothing));
86+
87+
8088

8189
m_UseQuaternionSynchronization = serializedObject.FindProperty(nameof(NetworkTransform.UseQuaternionSynchronization));
8290
m_UseQuaternionCompression = serializedObject.FindProperty(nameof(NetworkTransform.UseQuaternionCompression));
@@ -198,36 +206,42 @@ private void DisplayNetworkTransformProperties()
198206
if (networkTransform.SynchronizePosition)
199207
{
200208
DrawPropertyField(m_PositionInterpolationTypeProperty);
201-
// Only display when using Lerp.
202-
if (networkTransform.PositionInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
209+
210+
BeginIndent();
211+
if (networkTransform.PositionInterpolationType != NetworkTransform.InterpolationTypes.SmoothDampening)
203212
{
204-
BeginIndent();
205213
DrawPropertyField(m_SlerpPosition);
214+
}
215+
DrawPropertyField(m_PositionLerpSmoothing);
216+
if (networkTransform.PositionLerpSmoothing)
217+
{
206218
DrawPropertyField(m_PositionMaximumInterpolationTimeProperty);
207-
EndIndent();
208219
}
220+
EndIndent();
209221
}
210222
if (networkTransform.SynchronizeRotation)
211223
{
212224
DrawPropertyField(m_RotationInterpolationTypeProperty);
213-
// Only display when using Lerp.
214-
if (networkTransform.RotationInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
225+
226+
BeginIndent();
227+
DrawPropertyField(m_RotationLerpSmoothing);
228+
if (networkTransform.RotationLerpSmoothing)
215229
{
216-
BeginIndent();
217230
DrawPropertyField(m_RotationMaximumInterpolationTimeProperty);
218-
EndIndent();
219231
}
232+
EndIndent();
220233
}
221234
if (networkTransform.SynchronizeScale)
222235
{
223236
DrawPropertyField(m_ScaleInterpolationTypeProperty);
224-
// Only display when using Lerp.
225-
if (networkTransform.ScaleInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
237+
238+
BeginIndent();
239+
DrawPropertyField(m_ScaleLerpSmoothing);
240+
if (networkTransform.ScaleLerpSmoothing)
226241
{
227-
BeginIndent();
228242
DrawPropertyField(m_ScaleMaximumInterpolationTimeProperty);
229-
EndIndent();
230243
}
244+
EndIndent();
231245
}
232246
EndIndent();
233247
EditorGUILayout.Space();

0 commit comments

Comments
 (0)