fixed null bug in resync event

This commit is contained in:
JohnCorby 2021-11-17 20:31:32 -08:00
parent 79fb2cfe0b
commit 15a973d109
2 changed files with 37 additions and 14 deletions

View File

@ -82,6 +82,8 @@ namespace QSB.MeteorSync.Events
}
var refBody = qsbFragment.RefBody;
if (msg.IsThruWhiteHole)
{
var body = qsbFragment.Body;
var targetPos = refBody.transform.TransformPoint(msg.Pos);
var targetRot = refBody.transform.TransformRotation(msg.Rot);
@ -91,6 +93,14 @@ namespace QSB.MeteorSync.Events
body.MoveToRotation(targetRot);
SetVelocity(body, targetVel);
body.SetAngularVelocity(targetAngVel);
}
else
{
var targetPos = refBody.transform.TransformPoint(msg.Pos);
var targetRot = refBody.transform.TransformRotation(msg.Rot);
qsbFragment.AttachedObject.transform.position = targetPos;
qsbFragment.AttachedObject.transform.rotation = targetRot;
}
});
}
}

View File

@ -1,4 +1,6 @@
using QSB.WorldSync;
using OWML.Common;
using QSB.Utility;
using QSB.WorldSync;
using UnityEngine;
namespace QSB.MeteorSync.WorldObjects
@ -26,9 +28,20 @@ namespace QSB.MeteorSync.WorldObjects
public DetachableFragment DetachableFragment;
public bool IsThruWhiteHole => DetachableFragment != null &&
DetachableFragment._sector._parentSector == MeteorManager.WhiteHoleVolume._whiteHoleSector;
public OWRigidbody RefBody => IsThruWhiteHole ? MeteorManager.WhiteHoleVolume._whiteHoleBody :
Locator._brittleHollow._owRigidbody;
public OWRigidbody Body => IsThruWhiteHole ? AttachedObject.transform.parent.parent.GetAttachedOWRigidbody() : null;
public OWRigidbody RefBody => IsThruWhiteHole ? MeteorManager.WhiteHoleVolume._whiteHoleBody : Locator._brittleHollow._owRigidbody;
public OWRigidbody Body
{
get
{
if (IsThruWhiteHole)
{
return AttachedObject.transform.parent.parent.GetAttachedOWRigidbody();
}
DebugLog.ToConsole($"{LogName} - trying to get rigidbody when not thru white hole. "
+ "did you mean to get the transform instead?", MessageType.Error);
return null;
}
}
/// what the leash length will be when we eventually detach and fall thru white hole
public float LeashLength;