transform.collider.bounds.Intersects does not work!!

Hi,

I have a main object that some other objects are toching that.now i want to send message to these objects form main object.
This is my code,but transform.collider.bounds.Intersects does not work correctly.main object send message to all of colliders not only to colliders that are touching it!

    void OnCollisionEnter(Collision collision)
{
        Collider[] colliders = Physics.OverlapSphere(myTransform.position, 0.5f);
        foreach (Collider hit in colliders)
        {
            if (myTransform.collider.bounds.Intersects(hit.collider.bounds) && (hit.transform.tag == "Box")
            {
                hit.collider.transform.SendMessage("Change");
            }
        }
}

1 Answer

1

I have been using this recently and found that bounds creates a box around you collier and does not take up the collides shape, therefore if your collier is spherical, cylindrical or otherwise it will report collisions that have not hit the collision mesh but are inside the bounding box of the object.

also the bounds box will not rotate with you object it will remain to align with world xyz

Hope that is helpful.