Fix dynamic props from vessel when under parent body

This commit is contained in:
Noah Pilarski 2024-06-04 18:36:33 -04:00
parent e56a3e6440
commit 3f337a6ad7
2 changed files with 40 additions and 0 deletions

View File

@ -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<OWRigidbody>();
_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<GravityVolume>();
if (gravity != null) gravity.GetComponent<OWTriggerVolume>().AddObjectToVolume(_body.GetComponentInChildren<ForceDetector>().gameObject);
}
}

View File

@ -165,6 +165,17 @@ namespace NewHorizons.Handlers
Object.Destroy(rfVolume.gameObject); Object.Destroy(rfVolume.gameObject);
} }
} }
if (hasParentBody)
{
foreach (OWRigidbody dynamicProp in vesselObject.GetComponentsInChildren<OWRigidbody>(true))
{
if (dynamicProp.GetComponent<NomaiInterfaceOrb>() == null)
{
dynamicProp.gameObject.AddComponent<FixPhysics>();
}
}
}
var attachWarpExitToVessel = system.Config.Vessel?.warpExit?.attachToVessel ?? false; var attachWarpExitToVessel = system.Config.Vessel?.warpExit?.attachToVessel ?? false;
var warpExitParent = vesselWarpController._targetWarpPlatform.transform.parent; var warpExitParent = vesselWarpController._targetWarpPlatform.transform.parent;