Spawn offset (#644)

## Improvements
- Added `offset` to player and ship spawn positions. By default it moves
them up by 4m to prevent clipping into the ground but this can be non
ideal in cramped spawn locations.
This commit is contained in:
Nick 2023-07-18 10:22:16 -04:00 committed by GitHub
commit 5202326fce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 7 deletions

View File

@ -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<SpawnPoint>();
@ -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;
}

View File

@ -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
{
/// <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>
/// If you spawn on a planet with no oxygen, you probably want to set this to true ;;)
/// </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.
/// </summary>
public bool isDefault;
}
[JsonObject]
public class ShipSpawnPoint : GeneralPropInfo {
public class ShipSpawnPoint : SpawnPoint
{
}
}

View File

@ -40,7 +40,8 @@ namespace NewHorizons.Handlers
var matchInitialMotion = SearchUtilities.Find("Player_Body").GetComponent<MatchInitialMotion>();
if (matchInitialMotion != null) UnityEngine.Object.Destroy(matchInitialMotion);
Delay.StartCoroutine(SpawnCoroutine(2));
// Arbitrary number, depending on the machine some people die, some people fall through the floor, its very inconsistent
Delay.StartCoroutine(SpawnCoroutine(10));
}
}

View File

@ -3048,6 +3048,17 @@
"type": "object",
"additionalProperties": false,
"properties": {
"offset": {
"description": "Offsets the player/ship by this local vector when spawning. Used to prevent spawning in the floor. Optional: defaults to (0, 4, 0).",
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/MVector3"
}
]
},
"rotation": {
"description": "Rotation of the object",
"$ref": "#/definitions/MVector3"
@ -3089,6 +3100,17 @@
"type": "object",
"additionalProperties": false,
"properties": {
"offset": {
"description": "Offsets the player/ship by this local vector when spawning. Used to prevent spawning in the floor. Optional: defaults to (0, 4, 0).",
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/MVector3"
}
]
},
"rotation": {
"description": "Rotation of the object",
"$ref": "#/definitions/MVector3"