How to get contact points from a trigger?

shwick picture shwick · Jul 26, 2015 · Viewed 16.1k times · Source

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

Triggers don't give me contact points and colliders give me contact points but cause a collision.

I've tried disabling collisions when using colliders in the hopes of getting a collision enter callback but not having the collision actually occur, but no luck.

So how do I get contact points from a trigger? Or how do I get a collision callback with rigidbodies without causing a collision?

Basically I have a circle that I want to act as radar, but I'd like it to be fairly accurate with contact points too.

Answer

Nain picture Nain · Jul 27, 2015

You can get point of contact using OnTriggerEnter function

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