I added the below workaround script on the landing pads, so the player could have a safe landing without the rocket toppling over after game over. Note that in my world X-axis points towards the camera, Y up and Z to the right. You could add the same on ground, but IMO the rocket falling if it lands on “uneven” ground instead of the landing pad is more a feature than a bug
using UnityEngine;
/**
* A hack to stop rocket from rotation when it's landed. Prevents it from keeling over on its own after the game is over.
*/
public class SafefLanding : MonoBehaviour
{
private string playerTag = "Player";
private Rigidbody playerBody;
// Start is called before the first frame update
void Start()
{
var player = GameObject.FindGameObjectWithTag(playerTag);
if (player != null)
{
playerBody = player.GetComponent<Rigidbody>();
}
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.CompareTag(playerTag) && playerBody != null)
{
// TO DO: disable only if player got the rocket "straight enough"
playerBody.useGravity = false;
playerBody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
}
}
private void OnCollisionExit(Collision collision)
{
if (collision.collider.CompareTag(playerTag) && playerBody != null)
{
playerBody.useGravity = true;
playerBody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
}
}
}