Skip to content

fix: NetworkTransform rotation delta check false positives #1890

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

Conversation

NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Apr 20, 2022

Delta rotation checking was producing false positive results. This PR fixe this issue by using Mathf.DeltaAngle.
MTT-3370

Changelog

  • Fixed: NetworkTransfrom generating false positive rotation delta checks when rolling over between 0 and 360 degrees.

Testing and Documentation

  • Includes integration test.

MTT-3370
This fixes the issue with false positive rotation deltas while also assuring the threshold values cannot be set below the minimum threshold value.
this tests the fix for the rotation delta check and roll over from 0 to 360 degrees.
@NoelStephensUnity NoelStephensUnity changed the title fix: 3370 networktransform delta rotation check fix: NetworkTransform rotation delta check false positives Apr 20, 2022
Comment on lines 18 to 21
public const float ThresholdMinimum = 0.001f;
public const float PositionThresholdDefault = 0.001f;
public const float RotAngleThresholdDefault = 0.01f;
public const float ScaleThresholdDefault = 0.01f;
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering about using Mathf.Epsilon for these... any thoughts?

Copy link
Collaborator Author

@NoelStephensUnity NoelStephensUnity Apr 20, 2022

Choose a reason for hiding this comment

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

I think that my original thought on that is it could encourage a flawed design for detecting a change in a value to update over a network. Setting it to something like the Epsilon value ( 1.401298E-45) is such a small value that it is about the same as setting it to zero which can lead to scenarios where you are sending changes close to every frame due to minor jitter in things like rotation and/or moving along a slope with gravity applied.

Of course....I can think of scenarios where someone uses something like 0.001 as their game's 1 distance unit which would make detecting changes to that difficult...so setting the "minimum threshold" to a very low value could result in sending updates more frequently than desired (by default) but setting it too high could cause issues where the users world scale is not the default unity world scale (i.e. 1.0 tends to be the default in Unity).
(shrug)

I can see pro's and con's both ways. I picked 1/1000th of a "default world space unit" and 1/100th of a Euler degree for rotation....but maybe I just remove the restriction on scale and position values and delete ThresholdMinimum?
We want to keep the rotation thresholds as those make sense no matter what the user's world scale.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think 0.001f as defaults is fine but making 0.001f the threshold minimum might be a little limiting. If I disable gravity or make my rigidbody kinematic, it wouldn't move at all, not even epsilon and that shouldn't cause a re-replication since oldValue - newValue > epsilon would be false, right?
also I feel like we could have tests just testing these ranges too.
so if I were to sum it up, I think we should keep sensible defaults as 0.01f & 0.001f but make epsilon the min value for the ranges.

NoelStephensUnity and others added 2 commits April 20, 2022 15:12
Making the StopStartRuntimeTests derive from the NetcodeIntegrationTest to avoid the scenario where a specific platform/desktop is running slow for some reason and it take longer than the default NetcodeIntegrationTestHelpers.WaitForClientsConnected's 1 second.  Since it now derives from NetcodeIntegrationTest it will also handle cleaning up everything properly in the event the clients truly cannot connect. and not leave behind artifacts in the test runner scene and/or DDOL that would cause all tests that proceeded StopStartRuntimeTests to fail as well.
/// </summary>
/// <param name="transform">transform to apply</param>
/// <returns>bool isDirty, bool isPositionDirty, bool isRotationDirty, bool isScaleDirty</returns>
internal (bool isDirty, bool isPositionDirty, bool isRotationDirty, bool isScaleDirty) ApplyLocalNetworkState(Transform transform)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is following the paradigm but at this point, should this mega-tuple be turned into a struct? The tuple signature is replicated at least 3 times in this file, and with this internal API you're exposing the tuple to outside classes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah... I know... :(
I am trying to be very selective about what I am changing in these PRs...actually this PR is only a portion of #1846 just so I can get this rotation fix in without any other changes blocking this (a higher priority fix).

@ThusWroteNomad What do you think? Switch that to a struct in this PR or make that a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a nice and simple separate PR proposing tuple -> struct would be great :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, once this gets merged I will whip up a quick PR for that.

Copy link
Contributor

@TwoTenPvP TwoTenPvP left a comment

Choose a reason for hiding this comment

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

👌🏻

@NoelStephensUnity NoelStephensUnity merged commit 83752c8 into develop Apr 21, 2022
@NoelStephensUnity NoelStephensUnity deleted the fix/mtt-3370-networktransform-delta-rotation-check branch April 21, 2022 14:08
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.

6 participants