Random Map Generator

Hello! You’re either here because you want to automatically generate a map, or you’re just interested in the code. I made this in about 3-4 hours so if there is a mistake please tell me and I’ll fix it.
Alright, that’s all, here you go.
You’re welcome in advance.

More Details:
This is all created in 1 simple and easy-to-use Bundle

  • The “X Distance” Input lets you choose how far you want to generate it in the X direction
  • The “Y Distance” Input lets you choose how far you want to generate it in the Y direction
  • “Generate” Input starts the Generation process, this may take a few seconds.
  • “Repeat” Input is the number of connections you want a single generator to spawn
  • “Max Connections” Input is the total number of connections that will spawn (Default set to 50)

@grazer I’ve seen quite a few people ask questions about this so would you consider adding this to the example page?

@ManiacPumpkin if you need me to adjust something on this for you I can

5 Likes

Optimized some things and added a level showcasing it with walls. (Also added a FPS counter)

3 Likes

It seems to be very promising, but does the random placement ever overlap each other or sometimes loop onto existing paths?

It don’t seem like an issue for single sprite objects, but I have very similar issues with loading hallway segments and I end up with walls where walls shouldn’t be.

After practicing on it for a bit, it seems to be working very smoothly. I haven’t encountered any issues with it.

The only thing I’m looking for is that I don’t want the walls to touch. I’ve seen it generate areas such as 2x2 or 2x3 red cubes in a cluster and I’m not quite sure how the hallway segments would agree with that. But I could probably change this by changing the raycasts to double their length maybe? (Would this work). It should allow a block space in between parallel hallways.

2 Likes

This gave me a really good idea on what I should have done. Now I think I have a somewhat working design, thank you.

Also your example literally explained how the router worked, lol. I’ve been using randomizers and filters all this time when a simple router could have worked and saved so much space.

2 Likes

I think doubling the rays should work for creating separated hallways
Overlap does happen but I’ve only seen it when the generator tries to generate more than 1 connection, but when this does happen I have it delete the overlapping section instantly so that shouldn’t cause any problems.

I’ll make a demo version tomorrow with a slightly altered spawning pattern to make it look more like an actual structure

2 Likes

@ManiacPumpkin in Level 3 I added a better system that gives a much more structured look (And hallways no longer touch)

Also for anyone else that wants to use this, I optimized it a bit as well.
For the structured generation, it is recommended that the Repeat is set to a value greater than 1. This is because Rays were added for this to remove it if it is next to another generator, this creates hallways and won’t have it all jumbled together, making a much more structured look.

2 Likes