[SOLVED] Problem with random rooms

I have been trying to make random rooms for a game, but I don’t want the rooms to overlap each other, so I did the events:

I am using a 64 x 64 grid as standard size.

I create a builder with pathfinding behavior (Creador) (in 60x64 for both X and Y, since my grid is 120x120), then create an object named Final (End) that will be used to know where the builder will end its path. Assign a value to a scene variable named “EscalaCuarto” (RoomScale).

Repeat 10 times:

  • Create an object named room (64x64, origin in 32x32 as every object in my file) and change its scale to the value of the variable RoomScale. Use the pathfinding move to get the path for the next room. Calculate the new scale and save the end of the path, both X and Y in variables in the builder object.
  • Change the scale of Final to RoomScale so I know how big the next room will be and move Final to the place where the next room should be create. (The info is just to debug)
  • If The value of the variables in the builder are lower or higher than the limits (11x64 in each side) or if the Final object collides with a previous room, then a new path is calculated, the variables are set again and Final goes to the new possible room place.
  • When a valid spot is finally found, I move the builder to said spot and the repeat starts again

The thing driving me crazy is, sometimes it works fine, no rooms overlapping, but most times I end with rooms overlapping.


I changed the code so now I use a while and a condition only, looking like this:

And it works most of the times, yet with a big fail:

If I use the Final X position, or if I use a RandomInRange event the variable EscalaCuarto (RoomScale) seems to not be refreshed making all the rooms the same size.

The problem seems to be the detection of the collision between the builder and the previous made room. I have tried changing the scale, and changing the size, yet no avail. Time to go backwards. Make them as big as they need to be, and shrink them as needed.

Maybe the collision mask isn’t updated in a proper way, or fast enough to be test.

Ok. Finally got it with a “Microsoft” way to handle it: “There is no Error. If you document it well, you can say it is a Funtion”.

The events are working, I have a zoom so you can look the whole map being build, and it will be one of the game points. “Look the world grow before your eyes.”

The events make big rooms, very important… so important they delete any wall or corridor touching them. Then a size for the corridor piece is set and it grows toward another good room spot. Due workers laziness corridors may touch, but never overlap, this may lead to dead ends, but in the end, there will be always a way to go from A to B.

The walls around the rooms and corridors are kept (laziness), and everything else is clean, leaving a nice set of rooms (Even the corridors are room, but littler), ready to be populated with external layouts of the correct size.

Took me a little; but finally works :smiley:


Starting with the population tests. As you can see in the map, now there are horizontal rooms with floor and ceiling, and vertical rooms with platforms to climb.

I think I’ll need a group of variables, one for each size of corridor and room, saving the amount of rooms’ combinations so I can use a RandomInRange.


You should change the post as solved