nre fix and cleanup

This commit is contained in:
Aleksander Waage 2020-08-14 22:59:18 +02:00
parent 5bb2784c4f
commit 504e4c82e6
2 changed files with 3 additions and 7 deletions

View File

@ -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));
}
}

View File

@ -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);
}