From 114af7ef269ea178b1a26b2291cac588ae9b0538 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 17 Jul 2023 10:26:44 -0400 Subject: [PATCH] Allow setting spawn offset --- .../Builder/General/SpawnPointBuilder.cs | 10 ++++++---- NewHorizons/External/Modules/SpawnModule.cs | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index 4ae1084b..591defb4 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -21,7 +21,6 @@ namespace NewHorizons.Builder.General if (module.playerSpawn != null) { GameObject spawnGO = GeneralPropBuilder.MakeNew("PlayerSpawnPoint", planetGO, null, module.playerSpawn); - spawnGO.SetActive(false); spawnGO.layer = Layer.PlayerSafetyCollider; playerSpawn = spawnGO.AddComponent(); @@ -31,8 +30,7 @@ namespace NewHorizons.Builder.General playerSpawn._triggerVolumes = new OWTriggerVolume[0]; // This was a stupid hack to stop players getting stuck in the ground and now we have to keep it forever - spawnGO.transform.position += 4f * spawnGO.transform.up; - spawnGO.SetActive(true); + spawnGO.transform.position += spawnGO.transform.TransformDirection(module.playerSpawn.offset ?? Vector3.up * 4f); } if (module.shipSpawn != null) @@ -57,7 +55,11 @@ namespace NewHorizons.Builder.General ship.transform.rotation = spawnGO.transform.rotation; // Move it up a bit more when aligning to surface - if (module.shipSpawn.alignRadial.GetValueOrDefault()) + if (module.shipSpawn.offset != null) + { + ship.transform.position += spawnGO.transform.TransformDirection(module.shipSpawn.offset); + } + else if (module.shipSpawn.alignRadial.GetValueOrDefault()) { ship.transform.position += ship.transform.up * 4f; } diff --git a/NewHorizons/External/Modules/SpawnModule.cs b/NewHorizons/External/Modules/SpawnModule.cs index 9a613bc7..5899b658 100644 --- a/NewHorizons/External/Modules/SpawnModule.cs +++ b/NewHorizons/External/Modules/SpawnModule.cs @@ -24,7 +24,17 @@ namespace NewHorizons.External.Modules [Obsolete("startWithSuit is deprecated. Use playerSpawn.startWithSuit instead")] public bool startWithSuit; [JsonObject] - public class PlayerSpawnPoint : GeneralPropInfo { + public class SpawnPoint : GeneralPropInfo + { + /// + /// Offsets the player/ship by this local vector when spawning. Used to prevent spawning in the floor. Optional: defaults to (0, 4, 0). + /// + public MVector3? offset; + } + + [JsonObject] + public class PlayerSpawnPoint : SpawnPoint + { /// /// If you spawn on a planet with no oxygen, you probably want to set this to true ;;) /// @@ -33,10 +43,13 @@ namespace NewHorizons.External.Modules /// Whether this planet's spawn point is the one the player will initially spawn at, if multiple spawn points exist. /// public bool isDefault; + + } [JsonObject] - public class ShipSpawnPoint : GeneralPropInfo { + public class ShipSpawnPoint : SpawnPoint + { } }