What would be a good way to notice when colliders side (2d box collider in this case) is completely in collision with other colliders?
My scene is non rotated box colliders and quite static.
My current idea is to detect collisions and grab Contac points to an array for each side of the collider, use them to build representation of colliders aligned with the side and see if there are any holes. I’m sure there must be a easier way to do this. Any suggestions?
Collider’s got a method called OverlapPoint you could use this to see if the 2 points of your collider are in a other collider. You can use the bounds to find the location of its corner vertices.
Thanks for the reply! Did not notice that function, that will certainly help.
What I am trying to accomplish is simple water behavior. The biggest problem is detecting situation like this:
Did I collide with floorObject?
– Get collision points
– Add collision points to collisionArray
Update
Loop collisionArray
Check if there is continuous surface below me by combining collision points in the array
– Check that combined collision points form an unified line
I was also thinking this the other way around, the floor objects detect collisions and send message to water object saying “hey, you collided with me” and water object would to pretty much the same things as above. They would register the water object they are colliding with. This way floor objects could send messages about their state changes to the water instead of water constantly checking if anything has changed.
Each side of the water object does an AreaCast a little bit outwards of itself. This will give me array of all colliders that are in collision range.
Sort this array by either X or Y value of colliders, so they are in left to right or bottom to top order.
Now I can do ColliderArray.Intersects(ColliderArray[i+1]) loop, which checks if the colliders that are physically next to each other have any gaps between them.
From that loop I can grab position of the ‘holes’ (red circles in image above) to another array and do stuff like start leaking water through holes quite easily.
I’m pretty satisfied with this system; it’s quite clean code wise and I can figure lots of easy optimizations to save performance. If anyone has ideas on how to improve this or approach this in totally different manner I’d appreciate your input!