From 3f337a6ad7d11ed7231defca21a783277e689156 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Tue, 4 Jun 2024 18:36:33 -0400 Subject: [PATCH] Fix dynamic props from vessel when under parent body --- NewHorizons/Components/FixPhysics.cs | 29 +++++++++++++++++++++++ NewHorizons/Handlers/VesselWarpHandler.cs | 11 +++++++++ 2 files changed, 40 insertions(+) create mode 100644 NewHorizons/Components/FixPhysics.cs diff --git a/NewHorizons/Components/FixPhysics.cs b/NewHorizons/Components/FixPhysics.cs new file mode 100644 index 00000000..245f144a --- /dev/null +++ b/NewHorizons/Components/FixPhysics.cs @@ -0,0 +1,29 @@ +using NewHorizons.Utility.OuterWilds; +using NewHorizons.Utility.OWML; +using System.Collections; +using UnityEngine; + +namespace NewHorizons.Components; + +[DisallowMultipleComponent] +public class FixPhysics : MonoBehaviour +{ + private OWRigidbody _body; + + private void Awake() + { + _body = GetComponent(); + _body._lastPosition = transform.position; + } + + private void Start() + { + var parentBody = _body.GetOrigParentBody(); + if (parentBody == null) return; + _body.SetVelocity(parentBody.GetPointVelocity(_body.GetWorldCenterOfMass())); + _body.SetAngularVelocity(parentBody.GetAngularVelocity()); + if (_body._simulateInSector) _body.OnSectorOccupantsUpdated(); + var gravity = parentBody.GetComponentInChildren(); + if (gravity != null) gravity.GetComponent().AddObjectToVolume(_body.GetComponentInChildren().gameObject); + } +} diff --git a/NewHorizons/Handlers/VesselWarpHandler.cs b/NewHorizons/Handlers/VesselWarpHandler.cs index 12859c3a..1cb3092b 100644 --- a/NewHorizons/Handlers/VesselWarpHandler.cs +++ b/NewHorizons/Handlers/VesselWarpHandler.cs @@ -165,6 +165,17 @@ namespace NewHorizons.Handlers Object.Destroy(rfVolume.gameObject); } } + + if (hasParentBody) + { + foreach (OWRigidbody dynamicProp in vesselObject.GetComponentsInChildren(true)) + { + if (dynamicProp.GetComponent() == null) + { + dynamicProp.gameObject.AddComponent(); + } + } + } var attachWarpExitToVessel = system.Config.Vessel?.warpExit?.attachToVessel ?? false; var warpExitParent = vesselWarpController._targetWarpPlatform.transform.parent;