Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Determining point of contact between two colliders

Discussion in 'Physics' started by Igor5582, Jul 5, 2020.

  1. Igor5582

    Igor5582

    Joined:
    Jul 5, 2020
    Posts:
    2
    Hello,

    I trying to find a way of determining the collision/intersection points between two mesh colliders.

    OnCollisionEnter(Collision) would have been ideal, however I am running my own physics equations which would be broken by Unity's handling of physics (I don't need the collision aspect of it). Applying isKinematic=True does not help, as it would have to be on both colliders, and OnCollisionEnter does not trigger in such cases.
    OnTriggerEnter does not provide collision information so this doesn't help either (although I am all in favor of using triggers to determine when I can analyze the collision).
    I've also tried Physics.ComputePenetration which is close to what I need, but only returns collision direction and distance (I also need position).

    I guess in other words I need an OnTriggerEnter which also returns Collision data (rather than just the collider).
    Ultimately, even a system which would tell me which of the vertices in MeshColliderA are penetrating MeshColliderB would suffice.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,434
    You may enable collision events in kinematic bodies by setting Project Settings > Physics > Contact Pairs Mode to "Enable All Contact Pairs".

    As you're using rigidbodies you may also want to take a look at Rigidbody.SweepTest:
    https://docs.unity3d.com/ScriptReference/Rigidbody.SweepTest.html
     
    rcalabrezi and Igor5582 like this.
  3. Igor5582

    Igor5582

    Joined:
    Jul 5, 2020
    Posts:
    2
    Big thank you for this information! Enabled Contact Pairs Mode and it works exactly as needed! Cheers!
     
    Edy likes this.