# How to detect if player made building is air-tight(2D)

So, I am making a 2D block based game. I need to be able to tell if a custom, player made building is completely air-tight (So pretty much detecting if it is a completed house, with no holes outside). I had an idea how to do this, but I don’t think it will work. Here was my first Idea-

So I was going to make an empty game object that would float around the inside of the building with ray casts on all sides checking to make sure there is a wall on all sides. When the game object hit a wall, it would go another way. If it found that there was a wall missing, it wouldn’t be air-tight. Problem is, this probably isn’t the best way to do this, and I don’t know how I would spawn it in the building in the first place(How I would be able to check if one needs to be spawned).

So, I don’t really know how to approach this. Steering me in the right direction would help me out a lot. If there is another post on this or a tutorial you know that could help me, I would appreciate if you could comment it.

Bonus: What would be a good way to get all the air blocks in the room (once it detects the room is air-tight) into a group? Any ideas for that would be greatly appreciated.

It depends how your grid system works. It would be easiest if you have a 2-dimensional int array that takes xy coordinates to set the contents of this coordinate, like 0 for nothing, 1 for wall, 2 for door or whatever. Then you can just iterate through all positions and check each one’s neighbors, so that when an “in-house” coordinate has a neighbouring “not-in-house” block, you know that it’s not airtight.

If you are using actual gameobjects for each grid space, you can either do the same, or use four raycasts for each in-house space.