From ef24245c60c2fee8fc66f5e9596310edef9541de Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 19 May 2022 17:05:09 -0400 Subject: [PATCH] Custom player/ship rotation upon warp (#128) Closes #128 --- .../Builder/General/SpawnPointBuilder.cs | 25 ++++++++++++++++--- NewHorizons/External/Modules/SpawnModule.cs | 2 ++ NewHorizons/Schemas/body_schema.json | 11 +++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index de26408e..5236b793 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -18,7 +18,16 @@ namespace NewHorizons.Builder.General spawnGO.transform.localPosition = module.PlayerSpawnPoint; playerSpawn = spawnGO.AddComponent(); - spawnGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, (playerSpawn.transform.position - planetGO.transform.position).normalized); + + if(module.PlayerSpawnRotation != null) + { + spawnGO.transform.rotation = Quaternion.Euler(module.PlayerSpawnRotation); + } + else + { + spawnGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, (playerSpawn.transform.position - planetGO.transform.position).normalized); + } + spawnGO.transform.position = spawnGO.transform.position + spawnGO.transform.TransformDirection(Vector3.up) * 4f; } if (module.ShipSpawnPoint != null) @@ -34,9 +43,17 @@ namespace NewHorizons.Builder.General var ship = GameObject.Find("Ship_Body"); ship.transform.position = spawnPoint.transform.position; - ship.transform.rotation = Quaternion.FromToRotation(Vector3.up, (spawnPoint.transform.position - planetGO.transform.position).normalized); - // Move it up a bit more - ship.transform.position = ship.transform.position + ship.transform.TransformDirection(Vector3.up) * 4f; + + if(module.ShipSpawnRotation != null) + { + ship.transform.rotation = Quaternion.Euler(module.ShipSpawnRotation); + } + else + { + ship.transform.rotation = Quaternion.FromToRotation(Vector3.up, (spawnPoint.transform.position - planetGO.transform.position).normalized); + // Move it up a bit more when aligning to surface + ship.transform.position = ship.transform.position + ship.transform.TransformDirection(Vector3.up) * 4f; + } ship.GetRequiredComponent().SetBodyToMatch(owRigidBody); diff --git a/NewHorizons/External/Modules/SpawnModule.cs b/NewHorizons/External/Modules/SpawnModule.cs index 1adb5996..6f17885c 100644 --- a/NewHorizons/External/Modules/SpawnModule.cs +++ b/NewHorizons/External/Modules/SpawnModule.cs @@ -4,7 +4,9 @@ namespace NewHorizons.External.Modules public class SpawnModule { public MVector3 PlayerSpawnPoint { get; set; } + public MVector3 PlayerSpawnRotation { get; set; } public MVector3 ShipSpawnPoint { get; set; } + public MVector3 ShipSpawnRotation { get; set; } public bool StartWithSuit { get; set; } } } diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index c4de4207..856f314f 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1099,8 +1099,17 @@ "$ref": "#/$defs/vector3", "description": "If you want the player to spawn on the new body, set a value for this. Press \"P\" in game with Debug mode on to have the game log the position you're looking at to find a good value for this." }, + "playerSpawnRotation": { + "$ref": "#/$defs/vector3", + "description": "Euler angles by which the player will be oriented." + }, "shipSpawnPoint": { - "$ref": "#/$defs/vector3" + "$ref": "#/$defs/vector3", + "description": "Required for the system to be accessible by warp drive." + }, + "shipSpawnRotation": { + "$ref": "#/$defs/vector3", + "description": "Euler angles by which the ship will be oriented." }, "startWithSuit": { "type": "boolean",