- Home /
Find all objects within mesh collider
Hi all,
I'm trying to wrap my head around for days, but i can't figure it out.
Situation: I have a mesh collider (like a bar) and i set it as a trigger. Now i'm try to make a script that let the owner of the collider find all the objects with a tag "enemy" within that collider.
Because of the mesh collider i can't use Physics.OverlapSphere or a detection within a range. OnTriggerEnter won't work either, because it won't detect enemies allready in the collider when it starts.
Hope someone can help! Thanks Mark
Why is it that OverlapSphere won't work ? Are the meshcolider and the objects it collides with in the same layer? Otherwise , you could assign them to a different layer and do a OverrlapSphere call for a specific layer$$anonymous$$ask.
Are these other object also mesh colliders? 'Coz that's going to be an additional problem unless they are all convex. I think disabling/enabling the colliders after the objects are in place may well cause the OnTriggerEnter to be fired.
They are on the same layer, but the mesh is no Sphere. If that doesn't matter, what is the radius variable for then?
OverlapSphere only checks against the AABBs of the colliders anyway, you won't want to do that I'd bet.
The other objects dont have mesh collider, so that's one problem less :-)
Answer by raybarrera · Mar 14, 2014 at 04:20 PM
You could try getting the collider's bounds, the using bounds.Contains to test for a point inside of it.
That's an AABB again, which is fine, but it "sounds" like the OP needs a mesh collider for something.
I guess what threw me off was that he mentioned Physics.OverlapSphere, but now seeing your guys' exchange, I think I agree with "flickering" colliders is the way to go.
Your answer
Follow this Question
Related Questions
Collision flag entering a tagged object's collider 2 Answers
Getting Objects from CheckSphere 0 Answers
Find all objects inside box collider 4 Answers
RaycastHit collider not showing correct tags 1 Answer
Fog On and Off Script Help! 2 Answers