- Home /
Select a group of gameobjects that are contiguous
Suppose you have several groups of objects that are touching each other, but each group is not touching the other.
How do you select each contiguous group -- if you start by selecting one of the game objects in one of the groups, how do you select the entire contiguous group that this object belongs to (i.e., all the other game objects in this group that touch each other).
Answer by Atrius · Apr 16, 2012 at 04:44 AM
Not sure how your "Selection" system works, but you should be able to use OnCollisionStay, I think.
This will allow you to check if that object is "Selected" and if so it will give you a collision list of all the objects that are colliding with it.
OnCollisionStay looks useful, but I am also trying to figure out the logic of selecting beyond what one object is currently touching (ie what the other ones touching it are touching, for the contiguous "mass")
Well, it's sounding like you need to create a recursive function. You could use Physics.OverlapSphere() to check on demand around an object, and then call the same function on all child colliders you find, and add them all to some sort of static/global list of selected objects.
for OverlapSphere, do you know what bounding volumes vs actual colliders in, when the refer to it in the note: "Currently this only checks against the bounding volumes of the colliders not against the actual colliders"
Sorry for late response. $$anonymous$$y assumption is that bounding box refers to Collider.bounds. Which is a simple rect encompassing the collider but not the actual collider shape. http://unity3d.com/support/documentation/ScriptReference/Bounds.html