- Home /
how to make physics.OverlapSphere check multiple colliders?
I want a way so physics.overlapsphere will check overlap on multiple colliders without making duplicates.
Example: object A is the parent of two colliders. When button 'X' is pressed, a message is sent to each object that may be inside the colliders. also, these two colliders overlap, so an object might be in both colliders at the same time, however the object will only receive the message once. How would this be done?
It is hard for me to puzzle out what you are trying to do here. I don't know what the sphere represents or where OverlapSphere() is being called. Note that OverlapSphere() returns a list of colliders, not just a single collider. As a word of caution, OverlapSphere checks against the bounding box of the collider, not against the collider itself.
you want to check all the Colliders in a specific radius, and if there are 2 legs that are on the same parent object, only return the collision information for one parent object.
I think you can loop through all the detected objects and find each parent object and put it in a generic list, and then run a command to delete duplicates on the generic list.
If this is helpful vote me up because I don't have enough points to rate questions
I'll try to be more specific: physics.overlapsphere is the only way I know how to perform a "Send$$anonymous$$essage" to all colliders inside another collider.
what I'm trying to do is do a "Send$$anonymous$$essage" to all colliders inside multiple colliders. does that make sense?
for example, there is a fire spread out over a large area, this fire requires multiple trigger colliders to cover its area.
If the player enters the collider for one part of the fire, he begins taking damage (Send$$anonymous$$essage, "Apply Damage", etc.). The thing is, some of the colliders overlap, and I don't want the player taking double damage when standing in those parts.
You might find these callbacks interesting in the $$anonymous$$onoBehaviour class:
OnCollisionEnter / OnTriggerEnter
OnCollisionExit / OnTriggerExit
OnCollisionStay / OnTriggerStay
Answer by jmatthews · Oct 09, 2013 at 01:24 PM
The easiest fix for this is to maintain a state in your player that tracks whether he's received flame damage this round or not. This will insure you have the outcome you're looking for and eliminate a bunch of edge cases you'll run into further down the road. In general I've always found that each object should control its own outcomes. It makes reasoning about your systems much easier.