Detecting overlapping room in a dungeon generator

I haven’t gotten around to making it yet, but basically the generator would just create a prefab starting room, then a prefab room connected randomly to one of the starting room’s door, then another connected to said previous room,etc for a specific number of room. When generating it, how would I check if a room is overlapping another one? just have collider on both and check if said colliders are colliding? or are there other ways?

(basically the dungeons would be like immortal redneck, except linear and with branching out of only 1 room max or something)

Hello there,

Usually when using this kind of generator, you want to map it to some kind of 2D (or 3D) grid. That way, you would know that there are rooms in positions [0,2] and [0,3], but not in [1,2] for example. If two rooms have the same X and Y, you know they’re overlapping and can do something about it. Though ideally, you would check before even generating the room if that space is already occupied. Some rooms may even be bigger and take up multiple spaces.

Now in your case, you could do a second pass after the rooms have been generated, and use distance checking to detect overlapping rooms. Each room would go through a list of all rooms (expect itself) and check the distance between them. Since you should know the size of both rooms, you should be able to deduce if they are overlapping or not, by comparing the distance to half the size of both rooms combined. But this may get tricky if your rooms have weird shapes or angles.

You could also do a sphere cast to detect nearby rooms, although I’ve never tried it to tell you if that would actually work as expected.

Otherwise, indeed, you could build a box (or some other shape) collider the exact size of your room, and detect collisions that way.

I hope those leads can help you.

Best,

~LegendBacon