From b3364522642af474a2f83b4d6098dc6215362984 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 11 Jun 2021 13:40:02 +0100 Subject: [PATCH] add debug logs to GetRelativeVelocity --- .../UnparentedBaseRigidbodySync.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/QSB/Syncs/RigidbodySync/UnparentedBaseRigidbodySync.cs b/QSB/Syncs/RigidbodySync/UnparentedBaseRigidbodySync.cs index b50f7a54..6fcded0e 100644 --- a/QSB/Syncs/RigidbodySync/UnparentedBaseRigidbodySync.cs +++ b/QSB/Syncs/RigidbodySync/UnparentedBaseRigidbodySync.cs @@ -270,8 +270,27 @@ namespace QSB.Syncs.RigidbodySync public float GetVelocityChangeMagnitude() => (_velocity - _prevVelocity).magnitude; - public Vector3 GetRelativeVelocity() - => ReferenceTransform.GetAttachedOWRigidbody().GetPointVelocity(AttachedObject.transform.position) - AttachedObject.GetVelocity(); + public Vector3 GetRelativeVelocity() + { + if (AttachedObject == null) + { + DebugLog.ToConsole($"Error - Trying to get relative velocity when AttachedObject is null.", MessageType.Error); + return Vector3.zero; + } + if (ReferenceTransform == null) + { + DebugLog.ToConsole($"Error - Trying to get relative velocity when ReferenceTransform is null. ({AttachedObject.name})", MessageType.Error); + return Vector3.zero; + } + var attachedRigid = ReferenceTransform.GetAttachedOWRigidbody(); + if (attachedRigid == null) + { + DebugLog.ToConsole($"Error - ReferenceTransform ({ReferenceTransform.name}) on {AttachedObject.name} has no attached OWRigidBody.", MessageType.Error); + return Vector3.zero; + } + var pointVelocity = attachedRigid.GetPointVelocity(AttachedObject.transform.position); + return pointVelocity - AttachedObject.GetVelocity(); + } private void OnRenderObject() {