Search Unity

Question Trying to comprehend Collision.Impulse

Discussion in 'Physics' started by ATMLVE, Feb 5, 2024.



    Jun 11, 2023
    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:
    Code (CSharp):
    1. public class PhysicsTest2 : MonoBehaviour
    2. {
    3.     public Rigidbody rb;
    5.     private void OnCollisionEnter(Collision collision)
    6.     {
    7.         float impulse = collision.impulse.magnitude / Time.fixedDeltaTime;
    8.         float impulse2 = collision.impulse.magnitude;
    9.         Debug.Log(impulse + ", " + impulse2);
    10.     }
    11. }
    This little cube has a mass of 1. Meanwhile, this is the Big Cube, the impactor, which I give a mass of 50:
    Code (CSharp):
    1. public class PhysicsTest : MonoBehaviour
    2. {
    3.     public Rigidbody rb;
    4.     public float magnitude;
    6.     void Start()
    7.     {
    8.         rb.AddForce(new Vector3(0, 0, -1) * magnitude, ForceMode.Acceleration);
    9.     }
    10. }
    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.
    Last edited: Feb 5, 2024
  2. Edy


    Jun 3, 2010
    Collision.impulse is actually useless. It seems to be the average of the impulses of the contact points in a collision. It might be used for informative purposes, but definitely not as a something physically meaningful.

    Instead, use Collision.GetContacts to get all the contact points of the collision. Each ContactPoint contains an impulse field, which is the actual physical impulse applied by that contact point as result of the collision.
    Last edited: Feb 6, 2024
    ATMLVE and codebiscuits like this.