I have a complicated mesh that doesn't need to have anything to do with physics. However, I need to be able to detect said mesh with a raycast from a point. I have several hundred of these objects that regularly get moved around and rescaled, so a mesh collider is way too computationally expensive - especially since I don't need any form of collision detection other than this raycast. However, the mesh is human-shaped, and is thus irregular enough that I can't just use lots of primitives, nor can I just check if the mouse point is within a specified area (since the area is far too complex to manually specify). Turning the mesh collider off when it's not relevant works a little, but the act of turning the collider on and off is ALSO computationally expensive enough to cause noticeable frame drops. What component or settings can I use in order to raycast a mesh without all the slowdown of a mesh collider?
A similar question was asked before so I'll just re-post the answer 'Kay' provided.
- Use compound colliders especially box and sphere s Rigidbody manual
- Always attach rigidbodies to moving items
- If you need more than one raycast consider using Physics.RaycastAll
- If the physics engine is to blame for significant frame rate Drops, check whether you can use layers to optimise calculations
- Use the profiler