- Home /
Best way to detect objects in custom-shaped zones.
I know that detecting object presence inside boxes / spheres area is rather easy with a OnTriggerStay function attached to a box / sphere collider. However, if I want to detect objects in a custom shaped-zone, I'm not sure how to proceed efficiently.
ex: Let's say I use a flamethrower weapon in a game and I want hit to deal x damage to enemy units. For that, I'd need to detect enemy objects that are in front on my flames (inside a cone-ish shape in front of my gun).
I've tried using Mesh colliders, but Unity's physics seems to take a hit when the collider spawns. For it to work properly, I'd need to load (by instantiating in the scene) all my custom colliders at the start of the game, but makes the loading time much longer.
The other idea I had was to simply subdivide my area in smaller box colliders, but that seems like a cheap workaround that may cause other problems.
I've also thought about using the Send Collision Message option with the Particle System component (when flames particle hit an enemy, collision message is sent to lower their hp), but it only works if i'm actually using a particle system.
What's the best way to target objects in custom-shaped zones ?