Procedural Map Generation Logic

Hello,
I’ve recently decided to finish an older project of mine I started, and in order to do so, I needed a complete map generation algorythm.
HOWEVER, I never did anything like that and I can’t come up with an idea. I tried googling up the logic of the algorithm but it seems either uncomplete or I just can’t understand the code they wrote (in C++/C#)
It suggested to have multiple values assigned to each room like 0 being “No Room”, 1 being “Dead end”, 2 being a corridor and so on.
Any suggestions on how to achieve this if you ever done it

2 Likes

Have you tried to add “roblox” in your search? if not that’s logic that your search engine comes up with C++ and C#. Just add this or search in this forum and you’ll find what you want. People have already said some ways. I never touched random map generation too, so I can’t give you the basics and people shouldn’t give you whole scripts on how to do it. However I can give some steps on how to make scripts. So first, plan out what you’ll do in the script by making a script that is just comments then, you can change the comments 1 by 1 to actual code, also, I would recommend not actually removing the comments so that it’s more readable. Thanks for reading.

2 Likes

Yep, I did.
But due to the lack of results with roblox, I decided to extand my field of research to other languages. What I care about is the logic, not the code itself. I need to understand it to manage to get something decent.
I’ll continue looking for it. Right now, I may have come up with something somewhat plausible, using Delauney and prims algorithm, along with a grid and an A* pathfinding program. I’ll keep this post update with the advancement made.
Thanks for your time

You can use a maze generation algorithm, there are quite a few and they are not that difficult to understand.
But it also depends on what you want to achieve, for example I made an automatically generated obby. the obstacles between one checkpoint and the next were prefabs. I just had to join them randomly to form a path. Something as simple as:

  • if I put one forward then I’ll put the next one forward, left or right.
  • if I put one to the right, then the next one will be to the right or forward.
  • if I put one to the left then the next one will be to the left or forward.

it was quite effective. Even the paths didn’t cross.

If you have trouble reading code from another language, just use AI to convert it to lua. you can also give it pseudocode and it will convert it to lua. That helps a lot.

A maze isn’t exactly the type of generation I’m looking for.
I have a set amount of rooms I need to place in a grid, and connect them together. A bit like a dungeon.
I’m stuck in the part of the computing of the path. I need to understand how to get it to compute a way to generate corridors so that it doesn’t overlap, loop, or end abruptly/nowhere.

Seeing this, I think the problem is that you’re missing a starting point. I made this unfinished script for you so that you can have one:

local PlacesTaken = {true}--true is the start point
local LastRoom = 1
local ROOMS_TO_GENERATE = 5 --I put it at 5 for example
local WIDTH_OF_THE_GENERATION_ZONE = 5--can be changed

for i = 1, ROOMS_TO_GENERATE do
	local RoomIsTaken = true
	local Time = time()--this is the start time of the while loop
	while true do
		local RandomNumber = math.random(1, 4)
		if RandomNumber ==  1 then
			RandomNumber = LastRoom - 1--gets the room to the left
		elseif RandomNumber == 2 then
			RandomNumber = LastRoom - WIDTH_OF_THE_GENERATION_ZONE--the width of the zone for the rooms it gets the room above
		elseif RandomNumber == 3 then
			RandomNumber = LastRoom + WIDTH_OF_THE_GENERATION_ZONE--the width of the zone for the rooms it gets the room under
		elseif RandomNumber == 4 then
			RandomNumber = LastRoom + 1--gets the room to the right
		end
		
		if not PlacesTaken[RandomNumber] then--if nil so not taken
			PlacesTaken[RandomNumber] = true--this is true
			local Room = game.ReplicatedStorage:FindFirstChild("RoomPreset"):Clone()--create the room, you can make more later
			Room.Position = game.Workspace:WaitForChild("nontoxicguy1").HumanoidRootPart.Position--This is a placeholder position for me to see clearly the rooms
			Room.Parent = game.Workspace--make the room parented to the workspace
			LastRoom = RandomNumber--without this line, the script would only change room every second
			break
		elseif time() - Time >= 1 then--if the script is stuck for 1 seconds on the same room, we change room
			LastRoom = RandomNumber(-10, 10)--change room
			Time = time()--update the time
		end
	end
end

As you see this script is not done yet, you gotta make the missing points, but here’s what this script does right now:

PROS

  • Creates rooms (in my test world they were 1x1x1 cubes)
  • Avoids being stuck at the same room for too much time
  • Rooms can be generated infinitely on one axis

CONS

  • Only works for me
  • Doesn’t give the rooms a position
  • Doesn’t have a system for connecting the rooms, you gotta maybe change the rooms model.
  • you gotta give a limit to the generation on one axis

I hope you’re still happy to have a starting point, thanks for reading.

One thing I did in my game is AnchorPoints. Basically, they are some sort of lego bricks that connects rooms together.
To put simply - parts in model that indicate where the other room should connect.