From 504e4c82e6c6f44f0c3c9cefa09d9a8bbe4ec7c3 Mon Sep 17 00:00:00 2001 From: Aleksander Waage Date: Fri, 14 Aug 2020 22:59:18 +0200 Subject: [PATCH] nre fix and cleanup --- QSB/TransformSync/PlayerSectorEvent.cs | 3 ++- QSB/TransformSync/TransformSync.cs | 7 +------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/QSB/TransformSync/PlayerSectorEvent.cs b/QSB/TransformSync/PlayerSectorEvent.cs index e108c10e..e73b758e 100644 --- a/QSB/TransformSync/PlayerSectorEvent.cs +++ b/QSB/TransformSync/PlayerSectorEvent.cs @@ -36,7 +36,8 @@ namespace QSB.TransformSync var transformSync = PlayerRegistry.GetTransformSync(message.SenderId); DebugLog.ToScreen($"{transformSync.GetType().Name} of ID {message.SenderId} set to {message.SectorName}"); - transformSync.SetReference(sector); + UnityHelper.Instance.RunWhen(() => transformSync.SyncedTransform != null, + () => transformSync.SetReference(sector)); } } diff --git a/QSB/TransformSync/TransformSync.cs b/QSB/TransformSync/TransformSync.cs index 9af9d2a4..3e721cd8 100644 --- a/QSB/TransformSync/TransformSync.cs +++ b/QSB/TransformSync/TransformSync.cs @@ -11,7 +11,6 @@ namespace QSB.TransformSync private const float SmoothTime = 0.1f; private bool _isInitialized; - private Transform _previousTransform; public Transform SyncedTransform { get; private set; } public Sector ReferenceSector { get; set; } @@ -103,12 +102,8 @@ namespace QSB.TransformSync public void SetReference(Sector sector) { ReferenceSector = sector; - _positionSmoothVelocity = Vector3.zero; - _rotationSmoothVelocity = Quaternion.identity; SyncedTransform.parent = ReferenceSector.transform; - var difference = sector.transform.position - SyncedTransform.parent.position; - SyncedTransform.parent = ReferenceSector.transform; - SyncedTransform.localPosition = SyncedTransform.localPosition + difference; + SyncedTransform.localPosition += sector.transform.position - SyncedTransform.parent.position; transform.position = ReferenceSector.transform.InverseTransformPoint(SyncedTransform.position); transform.rotation = ReferenceSector.transform.InverseTransformRotation(SyncedTransform.rotation); }