From 1b441d0c538fd58bafec8355d7b472b6c4f7f5ec Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 23 Mar 2023 22:40:55 -0400 Subject: [PATCH] Fix some warp exit stuff --- .../Builder/Props/GeneralPropBuilder.cs | 2 +- NewHorizons/Handlers/VesselWarpHandler.cs | 41 +++++-------------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/NewHorizons/Builder/Props/GeneralPropBuilder.cs b/NewHorizons/Builder/Props/GeneralPropBuilder.cs index 41a3319ec..d80ca2457 100644 --- a/NewHorizons/Builder/Props/GeneralPropBuilder.cs +++ b/NewHorizons/Builder/Props/GeneralPropBuilder.cs @@ -76,7 +76,7 @@ public static class GeneralPropBuilder go.transform.position = pos; go.transform.rotation = rot; } - if (alignRadial) + if (alignRadial && planetGO != null) { var up = (go.transform.position - planetGO.transform.position).normalized; go.transform.rotation = Quaternion.FromToRotation(Vector3.up, up) * rot; diff --git a/NewHorizons/Handlers/VesselWarpHandler.cs b/NewHorizons/Handlers/VesselWarpHandler.cs index dc4023f3c..b298010fc 100644 --- a/NewHorizons/Handlers/VesselWarpHandler.cs +++ b/NewHorizons/Handlers/VesselWarpHandler.cs @@ -63,23 +63,6 @@ public static void LoadVessel() _vesselSpawnPoint = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension").GetComponentInChildren(); } - public static void OnReceiveWarpedBody(OWRigidbody warpedBody, NomaiWarpPlatform startPlatform, NomaiWarpPlatform targetPlatform) - { - bool isPlayer = warpedBody.CompareTag("Player"); - if (isPlayer) - { - Transform player_body = Locator.GetPlayerTransform(); - OWRigidbody s_rb = Locator.GetShipBody(); - OWRigidbody p_rb = Locator.GetPlayerBody(); - Vector3 newPos = player_body.position; - Vector3 offset = player_body.up * 10; - newPos += offset; - s_rb.SetPosition(newPos); - s_rb.SetRotation(player_body.transform.rotation); - s_rb.SetVelocity(p_rb.GetVelocity()); - } - } - public static void TeleportToVessel() { var playerSpawner = GameObject.FindObjectOfType(); @@ -162,16 +145,6 @@ public static EyeSpawnPoint CreateVessel() vesselWarpController._whiteHole = newWhiteHole.GetComponentInChildren(); vesselWarpController._whiteHoleOneShot = vesselWarpController._whiteHole.transform.parent.Find("WhiteHoleAudio_OneShot").GetComponent(); - vesselWarpController._targetWarpPlatform.OnReceiveWarpedBody += OnReceiveWarpedBody; - - var attachWarpExitToVessel = system.Config.Vessel?.warpExit?.attachToVessel ?? false; - var warpExitParent = vesselWarpController._targetWarpPlatform.transform.parent; - var warpExit = GeneralPropBuilder.MakeFromExisting(vesselWarpController._targetWarpPlatform.gameObject, null, null, system.Config.Vessel?.warpExit, parentOverride: attachWarpExitToVessel ? warpExitParent : null); - if (attachWarpExitToVessel) - { - warpExit.transform.parent = warpExitParent; - } - vesselObject.GetComponent()._labelID = (UITextType)TranslationHandler.AddUI("Vessel"); var hasParentBody = !string.IsNullOrEmpty(system.Config.Vessel?.vesselSpawn?.parentBody); @@ -194,6 +167,17 @@ public static EyeSpawnPoint CreateVessel() GameObject.Destroy(rfVolume.gameObject); } } + + var attachWarpExitToVessel = system.Config.Vessel?.warpExit?.attachToVessel ?? false; + var warpExitParent = vesselWarpController._targetWarpPlatform.transform.parent; + + var planetGO = hasPhysics ? vesselObject.transform.parent.gameObject : null; + + var warpExit = GeneralPropBuilder.MakeFromExisting(vesselWarpController._targetWarpPlatform.gameObject, planetGO, null, system.Config.Vessel?.warpExit, parentOverride: attachWarpExitToVessel ? warpExitParent : null); + if (attachWarpExitToVessel) + { + warpExit.transform.parent = warpExitParent; + } vesselWarpController._targetWarpPlatform._owRigidbody = warpExit.GetAttachedOWRigidbody(); var hasZeroGravityVolume = system.Config.Vessel?.hasZeroGravityVolume ?? !hasParentBody; @@ -232,9 +216,6 @@ public static SpawnPoint UpdateVessel() VesselWarpController vesselWarpController = vectorSector.GetComponentInChildren(true); WarpController = vesselWarpController; - if (vesselWarpController._targetWarpPlatform != null) - vesselWarpController._targetWarpPlatform.OnReceiveWarpedBody += OnReceiveWarpedBody; - if (vesselWarpController._whiteHole == null) { GameObject whiteHole = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension/Sector_VesselBridge/Interactibles_VesselBridge/WhiteHole");