Skip to content

Commit

Permalink
Fix some warp exit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
xen-42 committed Mar 24, 2023
1 parent df41617 commit 1b441d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
2 changes: 1 addition & 1 deletion NewHorizons/Builder/Props/GeneralPropBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 11 additions & 30 deletions NewHorizons/Handlers/VesselWarpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,6 @@ public static void LoadVessel()
_vesselSpawnPoint = SearchUtilities.Find("DB_VesselDimension_Body/Sector_VesselDimension").GetComponentInChildren<SpawnPoint>();
}

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<PlayerSpawner>();
Expand Down Expand Up @@ -162,16 +145,6 @@ public static EyeSpawnPoint CreateVessel()
vesselWarpController._whiteHole = newWhiteHole.GetComponentInChildren<SingularityController>();
vesselWarpController._whiteHoleOneShot = vesselWarpController._whiteHole.transform.parent.Find("WhiteHoleAudio_OneShot").GetComponent<OWAudioSource>();

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<MapMarker>()._labelID = (UITextType)TranslationHandler.AddUI("Vessel");

var hasParentBody = !string.IsNullOrEmpty(system.Config.Vessel?.vesselSpawn?.parentBody);
Expand All @@ -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;
Expand Down Expand Up @@ -232,9 +216,6 @@ public static SpawnPoint UpdateVessel()
VesselWarpController vesselWarpController = vectorSector.GetComponentInChildren<VesselWarpController>(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");
Expand Down

0 comments on commit 1b441d0

Please sign in to comment.