I am making a lunar lander type game where you have to try and land onto a planet but what I want to do is to make it so that if you ship is going too fast (based on velocity) that you will crash and the scene will reload. My problem is that when the ship collides with the ground it shows that it collides but it does not reset the scene even though the ship is going faster than my velocity and I have no clue as to of why; because the collision and the scene changes are working correctly but the velocity detection is not?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ExplosionDetection : MonoBehaviour
{
public Rigidbody2D PlayerShip;
public Vector2 KillSpeed;
private int LoadSameScene;
private void Start()
{
LoadSameScene = SceneManager.GetActiveScene().buildIndex + 0;
}
private void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.CompareTag("Player"))
{
Debug.Log("Collision Detected");
if (PlayerShip.velocity.y<KillSpeed.y)
{
SceneManager.LoadScene(LoadSameScene);
}
}
}
}