- Home /
Detecting a collider in 3D space.
Simple question; what is the simplest and most performance-efficient method for determining whether a collider exists at a specific point in 3D space?
I will need to do this maybe ~8-16 times per active rigidbody in my scene, per FixedUpdate.
What kind of collider: box, sphere, mesh? If mesh, is it convex?
If the collider is convex, first do the bounds check that @Jamora suggests. Then you can Raycast from some distant point to see if you get a hit. Use Collider.Raycast() to raycast against the specific collider rather than a more general Physics.Raycast().
Answer by Jamora · Aug 14, 2013 at 05:39 PM
You can loop over all of your colliders and check Bounds.Contains.
To get more performance, you could somehow partition your colliders so that the search space is as small as possible. Managing this will probably take more CPU cycles than it's worth if you have moving colliders.
Hm, this does seem more useful than everything I've thought of so far, but it doesn't take all the potential collider shapes into account...
I might just go with this for now anyway.