I want to detect when this object hits the ground with great enough force but it never works.
I used Debug.Log
to see what is happening and for some reason 3.78
is not greater than 1
. I have been trying to figure this out for a day but never found similar issues on the internet. I never apply any forces to the Rigidbody
, I just let gravity do its thing.
This code is written inside the OnCollisionEnter2D
method:
Debug.Log((Mathf.Abs(rb.velocity.y) > hitMagnitude / 2f).ToString() + ", " + Mathf.Abs(rb.velocity.y).ToString() + ", " + hitMagnitude.ToString());
if (collision.gameObject.CompareTag("Ground") && Mathf.Abs(rb.velocity.y) > hitMagnitude / 2f)
{
GotHit();
}