Skip to content

update: NetworkTransform SmoothDampening Updates #1443

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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

NoelStephensUnity
Copy link
Contributor

@NoelStephensUnity NoelStephensUnity commented Mar 14, 2025

Select the type of change:

  • Small Changes - Typos, formatting, slight revisions
  • New Content - New features, sections, pages, tutorials
  • Site and Tools - Updates, maintenance, and new packages for the site and Docusaurus

Purpose of the Pull Request:
This includes NetworkTransform updates based on PR-3337 as well as some updates to the over-all NetworkTransform documentaiton.

This also includes additional updates to NetworkTransform in general.

1st pass updates to NetworkTransform
NoelStephensUnity added a commit to Unity-Technologies/com.unity.netcode.gameobjects that referenced this pull request Mar 14, 2025
This PR fixes the issue with double lerping by providing two types of
interpolators to select from while also exposing the
`MaximumInterpolationTime` for each respective interpolator type. Smooth
Dampening is added as an alternative to using lerp for each respective
interpolator (position, rotation, and scale).

This PR includes a few new additions:
- Additional updates to the inspector view which allows for interpolator
type selection and if available additional properties associated with
the interpolator.

![image](https://github.com/user-attachments/assets/f643c015-646f-4c1a-a979-05a6287b41d7)

![image](https://github.com/user-attachments/assets/335cd68d-98fd-44b7-b6f3-88c4d44a60fd)

![image](https://github.com/user-attachments/assets/63c6d44c-09a4-4bad-b74e-46218a3a4b8c)

![image](https://github.com/user-attachments/assets/d966dd7c-0c82-4bcd-85ce-e7cf8455d3a6)
- A new `NetworkTimeSystem.TickLatency` property that provides the
average latency of a client.
- An new `NetworkTime.FixedDeltaTimeAsDouble` property that returns a
`double` version of the `NetworkTime.FixedDeltaTime`.

This PR also starts the deprecation process for
`BufferedLinearInterpolator<T>.Update(float deltaTime, NetworkTime
serverTime)` as this method is only for internal testing purposes.


[MTTB-539](https://jira.unity3d.com/browse/MTTB-539)
[MTT-11338](https://jira.unity3d.com/browse/MTT-11338) -- Fixing
disabled tests

fix: #3112
close: #3112 

## Changelog

- Added: Interpolator types as an inspector view selection for position,
rotation, and scale.
- Added: A new smooth dampening interpolator type that provides a nice
balance between precision and smoothing results.
- Added: `NetworkTimeSystem.TickLatency` property that provides the
average latency of a client.
- Fixed: Issue where the `MaximumInterpolationTime` could not be
modified from within the inspector view or runtime.
- Changed: `BufferedLinearInterpolator<T>.Update(float deltaTime,
NetworkTime serverTime)` as being deprecated since this method is only
used for internal testing purposes.

## Testing and Documentation

- Includes integration test updates:
- `InterpolatorTests` was updated to changes and two disabled tests were
refactored and re-enabled.
- `NetworkTransformGeneral` includes additional TestFixture passes using
Smooth Dampening.
- `NetworktTransformTests` includes additional TestFixture passes using
Smooth Dampening.
- `NestedNetworkTransformTests` includes additional TestFixture passes
using Smooth Dampening.
- Includes updates and additions to public documentation
([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.
-->
@jabbacakes
Copy link
Collaborator

Just lemme know when you want me to look at this 👍

NoelStephensUnity added a commit to Unity-Technologies/com.unity.netcode.gameobjects that referenced this pull request Apr 3, 2025
…#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 <emma.mcmillan@unity3d.com>
@NoelStephensUnity NoelStephensUnity marked this pull request as ready for review April 10, 2025 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants