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

In NetworkTransform, a full snapshots get triggered even if only the position OR the rotation changed above the sensitivity value. #3572

Open
The2ndT opened this issue Jul 31, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@The2ndT
Copy link

The2ndT commented Jul 31, 2023

Describe the bug
If during an update cycle the rotation of an GameObject with a NetworkTransform (unreliable) component changes enough to be over the rotationSensitivity value, the rotationChanged flag gets set

rotationChanged = Quaternion.Angle(lastSnapshot.rotation, currentSnapshot.rotation) > rotationSensitivity;

At the same time the position of the GameObject changes less than the positionSensitivity value and positionChanged does not get set
positionChanged = Vector3.SqrMagnitude(lastSnapshot.position - currentSnapshot.position) > positionSensitivity * positionSensitivity;

In UpdateServerBroadcast then only the rotation value gets broadcasted
syncPosition && positionChanged ? snapshot.position : default(Vector3?),
syncRotation && rotationChanged ? snapshot.rotation : default(Quaternion?),
syncScale && scaleChanged ? snapshot.scale : default(Vector3?)

Afterwards the current snapshot (inlcuding the current position AND rotation values) are stored as the lastSnapshot and used for the next comparison, if the GameObject hast moved or was rotated.

[IMPORTANT] How can we reproduce the issue, step by step:

  • create a scene for client-server with Mirror
  • add a GameObject with the NetworkTransformUnreliable component
  • add a script that rotates the GameObject serverside continously with 0.1 degree and moves it 0.01 units in one direction per update cycle
  • set that rotation and position sensitivity to 0.05
  • start the server and the client
  • connect the client to the server
  • the GameObject's rotation and position should change on the server, but on the client only the rotation changes, not the position

Expected behavior
NetworkTransform updates position and rotation at least occationally, even when only one component is above its sensitivity value. In the given example, the rotation updates in every cycle, but the position updates in every 5th cycle when the accumulated position change exceeds the position sensitivity.

Desktop (please complete the following information):

  • OS: Windows
  • Build target: standalone
  • Unity version: 2020.3
  • Mirror branch: release 79.0.1

Additional context
Small example with one dimentional position and rotation.
changerate position: +0.8
changerate rotation: +1.5
position/rotaion sensitivities: 1.0

  • Time t = 0:
    • game object
      • pos = 0
      • rot = 0
    • snapshot
      • pos = 0
      • rot = 0
  • Time t = 1:
    • game object
      • pos = 0.8
      • rot = 1.5
    • checks
      • pos: 0.8 - 0.0 = 0.8 < 1.0 > not send
      • rot: 1.5 - 0.0 = 1.5 > 1.0 > send
    • new snapshot
      • pos = 0.8
      • rot = 1.5
  • Time t = 2:
    • game object
      • pos = 1.6
      • rot = 3.0
    • checks
      • pos: 1.6 - 0.8 = 0.8 < 1.0 > not send
      • rot: 3.0 - 1.5 = 1.5 > 1.0 > send
    • new snapshot
      • pos = 1.6
      • rot = 3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants