From 2b429c9b3a6acd01b7c32e58fcb81df9ceaceada Mon Sep 17 00:00:00 2001 From: SuperCables <47830337+SuperCables@users.noreply.github.com> Date: Thu, 28 Feb 2019 06:19:09 -0500 Subject: [PATCH] This doesn't sync slow rotating objects (#428) * This doesn't sync slow rotating objects The function sets lastRotation to the current rotation every frame, regardless of whether or not it detected a change. Because comparing two similar, but different Quaternions return true, only quickly rotating objects will return true; slow turning objects will return false, and the rotation will not be synced. By not updating lastRotation until a difference is spotted, any rotation will be synced. This fix allowed my slow rotating spaceship to sync rotation. TL;DR lastRotation should be the last time this function returned true, not the rotation last frame. * Update NetworkTransformBase.cs --- Assets/Mirror/Components/NetworkTransformBase.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Assets/Mirror/Components/NetworkTransformBase.cs b/Assets/Mirror/Components/NetworkTransformBase.cs index a8fa8b0bc..6250fdd2a 100644 --- a/Assets/Mirror/Components/NetworkTransformBase.cs +++ b/Assets/Mirror/Components/NetworkTransformBase.cs @@ -297,10 +297,16 @@ bool HasMovedOrRotated() bool rotated = lastRotation != targetComponent.transform.rotation; // save last for next frame to compare - lastPosition = targetComponent.transform.position; - lastRotation = targetComponent.transform.rotation; - - return moved || rotated; + // (only if change was detected. otherwise slow moving objects might + // never sync because of C#'s float comparison tolerance. see also: + // https://github.com/vis2k/Mirror/pull/428) + bool change = moved || rotated; + if (change) + { + lastPosition = targetComponent.transform.position; + lastRotation = targetComponent.transform.rotation; + } + return change; } // set position carefully depending on the target component