Skip to content
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

fix: buffered linear interpolator jitter and exposing more properties #3355

Open
wants to merge 40 commits into
base: develop-2.0.0
Choose a base branch
from

Conversation

NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Mar 21, 2025

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 adds a 3rd interpolator type: LerpExtrapolateBlend

Lerp, Extrapolate, and Blend

Uses a 3 to 5 phase lerp towards the target, extrapolate towards the target, blend the two results, and (optionally) smooth the final value.

  • The first phase lerps towards the current tick state update being processed.
  • The second phase lerps unclamped (extrapolates) towards the current tick state update and will extrapolate this value up to a calculated maximum delta time. The maximum delta time is the tick latency, calculated from an estimated RTT each time the network time is updated, plus the InterpolationBufferTickOffset. The sum is multiplied by the tick frequency (one over tick rate).
  • The third phase lerps between the results of the first and second phases by the current delta time.
  • The fourth phase (optional) performs a lerp smoothing where the current respective transform value is lerped towards the result of the third phase at a rate of delta time divided by the respective max interpolation time.
    • LerpExtrapolateBlend and SmoothDampening have an additional interplation pass during smooth lerping that interpolates 1/3rd towards the target and then smooths the result of that based on the MaximumInterpolationTime divided into the delta time.

Changelog

  • Added: LerpExtrapolateBlend interpolation type that provides users with something between standard lerp and smooth dampening.
  • 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.

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)

Getting closer to what I am hoping to achieve.
Adding more properties for users to adjust as well as an additional interpolation type as there are various use cases where one model doesn't fit all genres.
Just wrapping some code that I will be removing anyway before marking this PR ready for review.
Adding some line breaks in new XML API documentation.
Updating PositionMaxInterpolationTime, RotationMaxInterpolationTime, and ScaleMaxInterpolationTime to be set when `NetworkTransform.SetMaxInterpolationBound` is invoked.
updating the xml api
Defaulting the lerp smoothing to true (like it was originally when you couldn't enable/disable it).
Removing debug script from NetworkManager.
Forgot to remove the components namespace when removing the debug script.
Only apply the InterpolationBufferTickOffset once.
Bumping the default tick latency down to 1.
Fixing some additional issues and trying to find a reasonable balance.
Updating NetworkTransformGeneral to test all interpolator types and adding a means to getting verbose debug logs,
Fixing a mistake on SD final lerp pass.
making the added verbose log history internal to avoid PVP issue.
making sure the first entry is set to having reached its final point.
Adding debug information to better understand the failure.
Sigh...
Removing the teleport I put in last week.
Dumb floating point precision.
Minor adjustment UpdateInterpolation
Removing commented out code.
NetworkTransform using the realtime provider time system to be more compatible with the integration test time travel system.
providing a bit more time and reducing the target position to provide enough time to for interpolation.
Removing some of the debug information.
Fixing whitespace issue.
Adding a smooth lerp and non-smooth lerp pass.
Adding additional LerpExtrapolateBlend passes
Minor adjustments after a long debug session...
- Removed the lerp smoothing parameter and made it an internal bool (don't need to add to API and it should be set through the NetworkTransform anyway).
- Added additional BufferedLinearInterpolator debug code.
- Added additional PreUpdate pass for NetworkTransforms using Rigidbody motion in order to reset a fixed time delta.
- Added incemental fixed time delta when the FixedUpdate is invoked multiple times within a single frame.
- Added internal time sync counter.
- Added a "1/3rd" rule to smooth dampening and LerpExtrapolateBlend when smooth lerp is enabled in order to still be able to balance between smoothing the final lerped value and reaching the target (or getting much closer).
removing the lerpSmoothing parameter from xml API documentation.
One more removal of the same lerpSmoothing parameter in comments.
@NoelStephensUnity NoelStephensUnity marked this pull request as ready for review March 26, 2025 21:32
@NoelStephensUnity NoelStephensUnity requested a review from a team as a code owner March 26, 2025 21:32
Some adjustments to  handle coming to a stop and to no longer clamp the timespan between state updates for LerpExtrapolateBlend and SmoothDampening.
Adding fixed delta to server time (if it is of any value then multiple fixed updates have run within a single frame).
Updated XML API documentation (again).
XML API stuff.
arrg... lists! PVP!
2 more...evidently you can't use <list> within a <param>
Quaternion approximation calculation was wrong.
Adding [MethodImpl(MethodImplOptions.AggressiveInlining)] to float, Vector3, and Quaternion LinearBufferInterpolator methods.
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.

1 participant