Hey. I am a beginner making a simple lunar lander and I’m having trouble testing for velocity when the lander hits the ground. The problem is that my velocity is set to 0 as soon as the lander collides with the ground so when I test to see if it was above the threshold it will always return as no.
Here’s the code:
void Update()
{
//basic move controls
if (Input.GetKey("up"))
{
rb2D.AddForce(transform.up * thrust);
}
if (Input.GetKey("left"))
{
transform.Rotate(0, 0, rotateSpeed);
}
if (Input.GetKey("right"))
{
transform.Rotate(0, 0, rotateSpeed * -1);
}
//for DeBug purposes
if (Input.GetKeyUp("l"))
{
print(rb2D.velocity.x);
print(rb2D.velocity.y);
}
}
void OnCollisionEnter2D(Collision2D collsion)
{
float crashVelocity = 3.0f;
//check if X velocity is too high
if (crashVelocity < Mathf.Abs(rb2D.velocity.x))
{
print("CRASH X");
}
//check if Y velocity is too high
if (crashVelocity < Mathf.Abs(rb2D.velocity.y))
{
print("CRASH Y");
}
}