Allow setting spawn offset

This commit is contained in:
Nick 2023-07-17 10:26:44 -04:00
parent c79ff48966
commit 114af7ef26
2 changed files with 21 additions and 6 deletions

View File

@ -21,7 +21,6 @@ namespace NewHorizons.Builder.General
if (module.playerSpawn != null) if (module.playerSpawn != null)
{ {
GameObject spawnGO = GeneralPropBuilder.MakeNew("PlayerSpawnPoint", planetGO, null, module.playerSpawn); GameObject spawnGO = GeneralPropBuilder.MakeNew("PlayerSpawnPoint", planetGO, null, module.playerSpawn);
spawnGO.SetActive(false);
spawnGO.layer = Layer.PlayerSafetyCollider; spawnGO.layer = Layer.PlayerSafetyCollider;
playerSpawn = spawnGO.AddComponent<SpawnPoint>(); playerSpawn = spawnGO.AddComponent<SpawnPoint>();
@ -31,8 +30,7 @@ namespace NewHorizons.Builder.General
playerSpawn._triggerVolumes = new OWTriggerVolume[0]; 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 // 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.transform.position += spawnGO.transform.TransformDirection(module.playerSpawn.offset ?? Vector3.up * 4f);
spawnGO.SetActive(true);
} }
if (module.shipSpawn != null) if (module.shipSpawn != null)
@ -57,7 +55,11 @@ namespace NewHorizons.Builder.General
ship.transform.rotation = spawnGO.transform.rotation; ship.transform.rotation = spawnGO.transform.rotation;
// Move it up a bit more when aligning to surface // 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; ship.transform.position += ship.transform.up * 4f;
} }

View File

@ -24,7 +24,17 @@ namespace NewHorizons.External.Modules
[Obsolete("startWithSuit is deprecated. Use playerSpawn.startWithSuit instead")] public bool startWithSuit; [Obsolete("startWithSuit is deprecated. Use playerSpawn.startWithSuit instead")] public bool startWithSuit;
[JsonObject] [JsonObject]
public class PlayerSpawnPoint : GeneralPropInfo { public class SpawnPoint : GeneralPropInfo
{
/// <summary>
/// Offsets the player/ship by this local vector when spawning. Used to prevent spawning in the floor. Optional: defaults to (0, 4, 0).
/// </summary>
public MVector3? offset;
}
[JsonObject]
public class PlayerSpawnPoint : SpawnPoint
{
/// <summary> /// <summary>
/// If you spawn on a planet with no oxygen, you probably want to set this to true ;;) /// If you spawn on a planet with no oxygen, you probably want to set this to true ;;)
/// </summary> /// </summary>
@ -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. /// Whether this planet's spawn point is the one the player will initially spawn at, if multiple spawn points exist.
/// </summary> /// </summary>
public bool isDefault; public bool isDefault;
} }
[JsonObject] [JsonObject]
public class ShipSpawnPoint : GeneralPropInfo { public class ShipSpawnPoint : SpawnPoint
{
} }
} }