Surface with hole and Raycast - Which collider

Hi everyone,

I would like to know what is the best solution. Here is the setup :

  • A wall of a face with a hole
  • A bunch of objects behind
  • A Raycast to select object

What kind of collider should I use for the wall ?

The most optimized solution is a Box collider but how can I handle the hole ? A mesh collider is not the most optimized solution especially with Raycast.

Is there a way to set-up automatically multiple Box collider to match the shape of the wall and the hole ?

Thanks a lot !

In this case i would recommend a box collider for the wall, and a separate collider for the hole (preferably a basic collider for performance, like flat sphere or another box).

Then use RaycastAll instead of Raycast, and have the wall and hole colliders negate each other. So if you hit both of them, treat it like hitting none. That way any raycast going through the hole, it will hit both, and be treated as if it went through.