I’m trying to obtain the “impact force” between two rigid bodies. I’m trying to figure out how hard my physics-based character gets hit by a moving object.
After testing with the character and coming up bemused, I broke things down very simply. So what I have is a Big Cube which I push with a force into a little cube that registers the hit it takes from the Big Cube.
The little cube:
public class PhysicsTest2 : MonoBehaviour
{
public Rigidbody rb;
private void OnCollisionEnter(Collision collision)
{
float impulse = collision.impulse.magnitude / Time.fixedDeltaTime;
float impulse2 = collision.impulse.magnitude;
Debug.Log(impulse + ", " + impulse2);
}
}
This little cube has a mass of 1. Meanwhile, this is the Big Cube, the impactor, which I give a mass of 50:
public class PhysicsTest : MonoBehaviour
{
public Rigidbody rb;
public float magnitude;
void Start()
{
rb.AddForce(new Vector3(0, 0, -1) * magnitude, ForceMode.Acceleration);
}
}
To skip the values, I am seeing that dropping the little cube from a height of literally 0.4 units incurs higher values from the two debug logs than with the Big Cube impacting it at maybe 2 units per second, which has a mass of 50. I feel like unity is saying a person doing a little hop takes a bigger hit from their landing than getting hit by a truck. I am clearly misunderstanding something conceptually here, but I don’t know what it is.
Also I gave collision.relativeVelocity a shot and got even more confusing results, but I want it to be that higher mass objects impart a bigger return value anyway. Is my answer to just multiply by both masses? This can’t work always because the floor doesn’t have a rigidbody. What’s the point of collision.Impulse?
Edit: This is extremely perplexing. This is the collision with the ground:
A cube of mass 1 lands with a rigidbody.velocity of 0.3.
Collision impulse is 9.2.
This is when it gets hit by the big cube:
Big cube has a mass of 5000.
Clobbers it at a measly rigibody.velocity of 4.
and Collision impulse is 4.3.
I know effectively the ground has “infinite mass” I guess since it has no give it at all? But this clearly makes no intuitive sense at face value.