How to get contact points from a trigger?

I am in a situation where I need a 2d sensor that will not collide, but also give me contact points for a collision.

Triggers do not give me contact points, and colliders give me contact points, but they cause a collision.

I tried to turn off collisions when using colliders in the hope that the collision would cause a callback, but the collision would not occur, but it would fail.

So, how do I get contact points from a trigger? Or how do I get a collision call with rigid bodies without causing a collision?

Basically, I have a circle that I want to use as a radar, but I would like it to be pretty accurate with contact points too.

+4
source share
2 answers

OnCollisionEnter, rigidbody isTrigger false rigidbody isKinematic true, ,

 void OnCollisionEnter(Collision collision) {
        foreach (ContactPoint contact in collision.contacts) {
            Debug.DrawRay(contact.point, contact.normal, Color.white);
        }
+2

, OnTriggerEnter

OnTriggerEnter(Collider other)
{
    RaycastHit hit;
    if (Physics.Raycast(transform.position, transform.forward, out hit))
    {
        Debug.Log("Point of contact: "+hit.point);
    }
}
+3

Source: https://habr.com/ru/post/1599758/


All Articles