mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
copy without killing you
This commit is contained in:
parent
6ab184ef07
commit
a968308597
@ -96,8 +96,13 @@ public class AddPhysics : MonoBehaviour
|
|||||||
|
|
||||||
if (SuspendUntilImpact)
|
if (SuspendUntilImpact)
|
||||||
{
|
{
|
||||||
// suspend disables colliders, so have to use copy-pasted version
|
// copied from OWRigidbody.Suspend
|
||||||
Suspend();
|
_body._suspensionBody = parentBody;
|
||||||
|
_body.MakeKinematic();
|
||||||
|
_body._transform.parent = parentBody.transform;
|
||||||
|
_body._suspended = true;
|
||||||
|
_body._unsuspendNextUpdate = false;
|
||||||
|
|
||||||
_impactSensor.OnImpact += OnImpact;
|
_impactSensor.OnImpact += OnImpact;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -106,61 +111,6 @@ public class AddPhysics : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region copy-pasted from OWRigidbody
|
|
||||||
|
|
||||||
private void Suspend()
|
|
||||||
{
|
|
||||||
if (!_body._suspended)
|
|
||||||
{
|
|
||||||
if (_body._origParentBody != null)
|
|
||||||
{
|
|
||||||
Suspend(_body._origParent, _body._origParentBody);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_body._simulateInSector != null)
|
|
||||||
{
|
|
||||||
Suspend(_body._simulateInSector.GetOWRigidbody());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Debug.Log("Unable to suspend : " + _body.gameObject.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Suspend(OWRigidbody suspensionBody)
|
|
||||||
{
|
|
||||||
_body.Suspend(suspensionBody.transform, suspensionBody);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Suspend(Transform suspensionParent, OWRigidbody suspensionBody)
|
|
||||||
{
|
|
||||||
if (!_body._suspended || _body._unsuspendNextUpdate)
|
|
||||||
{
|
|
||||||
_body._suspensionBody = suspensionBody;
|
|
||||||
Vector3 vector = _body.GetVelocity() - suspensionBody.GetPointVelocity(_body._transform.position);
|
|
||||||
_body._cachedRelativeVelocity = suspensionBody.transform.InverseTransformDirection(vector);
|
|
||||||
_body._cachedAngularVelocity = (_body.RunningKinematicSimulation() ? _body._kinematicRigidbody.angularVelocity : _body._rigidbody.angularVelocity);
|
|
||||||
_body.enabled = false;
|
|
||||||
_body._offsetApplier.enabled = false;
|
|
||||||
if (_body.RunningKinematicSimulation())
|
|
||||||
{
|
|
||||||
_body._kinematicRigidbody.enabled = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_body.MakeKinematic();
|
|
||||||
}
|
|
||||||
_body._transform.parent = suspensionParent;
|
|
||||||
_body._suspended = true;
|
|
||||||
_body._unsuspendNextUpdate = false;
|
|
||||||
if (!Physics.autoSyncTransforms)
|
|
||||||
{
|
|
||||||
Physics.SyncTransforms();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private void OnImpact(ImpactData impact)
|
private void OnImpact(ImpactData impact)
|
||||||
{
|
{
|
||||||
_body.Unsuspend();
|
_body.Unsuspend();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user