A
A
Alex2022-01-26 01:14:12
Unity
Alex, 2022-01-26 01:14:12

How to find out which objects are in contact with the collider at the moment?

There is an OnTrigger event. There are districts. Is it possible in a certain place in the code to poll the collider after receiving a list of hits? To find out which objects currently have contact with the collider?
Or there are no ready-made solutions and this is possible only by implementing a certain sheet where objects will be written and deleted by OnTrigger events?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Farawa, 2022-01-26
@Farawa

OnTriggerStay

G
GFX Data, 2022-01-26
@ShockWave2048

Try the ComputePenetration() method

A
Alex, 2022-01-28
@alexjet73

Thanks to @ShockWave2048 I found the OverlapBox function nearby

void MyCollisions()
    {
        //Use the OverlapBox to detect if there are any other colliders within this box area.
        //Use the GameObject's centre, half the size (as a radius) and rotation. This creates an invisible box around your GameObject.
        Collider[] hitColliders = Physics.OverlapBox(gameObject.transform.position, transform.localScale / 2, Quaternion.identity, m_LayerMask);
        int i = 0;
        //Check when there is a new collider coming into contact with the box
        while (i < hitColliders.Length)
        {
            //Output all of the collider names
            Debug.Log("Hit : " + hitColliders[i].name + i);
            //Increase the number of Colliders in the array
            i++;
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question