Help and tips on procedural maze/facility generation

felt inspired by scp anomaly breach and wanted to make my own spin on CB

really not sure where to start in terms of generation tho, since i want the place to feel like an actual facility and not just a bunch of prefab rooms thrown together

main challenge is rooms with multiple exits since ive never done that before, just done procedural hallways a few years back. so im not really sure about what methods/techniques to use on something like this and ive never been able to find anything about it online outside of showcases

any tips/advice would be greatly appreciated

3 Likes

There’s a really great tool for Unity and Unreal called Dungeon Architect that you can take inspiration from. Sadly, it’s too awesome to have a Roblox equivalent, but maybe that will change in the future.

1 Like

My go-to for procedural generation is the WFC algorithm. It mimics quantum mechanics by using the principles of superposition, observation, and propagation and it’s fairly simple to implement in practice.

Succinctly put, it runs like this:

  1. Create a m×n grid of cells of which each cell is in a superposition (each cell is in all possible states at once)
  2. Pick the cell with the lowest entropy (that is, the least number of possible states) and “collapse” it (that is, set its state to one of the random states it could be in)
  3. Examine the neighbors of the collapsed cell and update their list of states depending on which state the collapsed cell is in
  4. Propagate this change until no more cells need to adjust their state
  5. Repeat steps 1–4 until either a) you reach a contradiction (at which point you can backtrack or restart) or b) each cell is collapsed to exactly one state

This algorithm is useful because it a) allows you to pre-define specific aspects of the map (such as forcing the corners to be walls or forcing a specific tile to be a specific room) and b) is highly tunable.

The only downsides are that you a) need to dedicate time creating pre-existing tiles to choose from and b) create a rule table of which tiles can be neighbors, considering things such as rotations and tile size

2 Likes

both do seem quite interesting, yet i was wanting to have cell sizes be different depending on what room gets placed down since im wanting more verticality and rooms with different sizes/functions since scpcb is quite flat due to its algorithm

might think about combining the 2 but that might be quite difficult

1 Like

In SCP: Containment Breach, the map generation system starts by creating a flat 2D grid. Then it places plots (spaces where rooms can go) onto that grid. Different areas of the game, like the 860 dimension, maintenance tunnels, or the main facility, each have their own map generation rules, but they all work in a similar way.

Once the plots are in place, the game decides which rooms to put where. The type of room (like a hallway, corner, T-junction, or dead-end) and its rotation depend on what’s around it - the neighboring plots to the north, east, south, and west.

Also, keep in mind that for NPCs to move through the map properly, you’ll need to use a pathfinding system like A* to help them find their way from one place to another, Roblox’s PathfindingService would act bad in ‘hallways with doors’ enviroment.

< LINKS >

Interesting videos from 2cola1 that you might will find usefull: https://youtu.be/XQoC1h54zJA?si=MOvmaYWnfbv7a47S, https://youtu.be/FWfM7h0IyoA?si=DEYPMppfLBFwtuIc.

Yni Viar’s scpcb-mapgen-v2 on GODOT engine: GitHub - Yni-Viar/scp-mapgen-godot: SCP-like facility map generator for Godot 4, you can try to research this one instead of original SCP CB’s messy pasta code.

1 Like

Hey @Wall_Dweller, how’s it going?

I’m currently working on an SCP: Containment Breach port for Roblox, and yeah map generators can be super confusing at first. Once you get the hang of them though, they’re actually pretty fun to mess around with.

In SCP:CB, the map generator starts with a 2D grid and uses a seed-based generation system to randomly place rooms, forming a maze like modular layout. It always makes sure essential rooms (like SCP-173’s chamber or the special rooms) are included and that everything is reachable, while still giving you different layouts for each zone (Light, Heavy, Entrance, etc).

In Luau, you can use 2D arrays to handle something similar. Here’s a basic setup example:

local MapTemp = {}
local MapName = {} -- MapName[x][y] = string (room type or special name)

for x = 0, MapWidth do
	MapTemp[x] = {}
	MapName[x] = {}
	for y = 0, MapHeight do
		MapTemp[x][y] = 0
		MapName[x][y] = ""
	end
end

When placing rooms, you’ll want to check neighboring cells to make sure connections line up properly (hallways, corners, T-junctions, crossroads, etc).

If you’re stuck making your generator, I can share my current code, it’s still a bit buggy and some seeds break the layout, but it’s a REALLY good starting point. And don’t stress it everyone struggles with map generation at first. I’m still working through some issues myself, especially with room model alignment, since different meshes have weird sizes or offsets, and it’s quite annoying actually lol.

I hope this helps you, have a nice day.

1 Like

Hi, I found very useful explanation video about map generation on YouTube.

Hi guys, I remade the system quickly and I made the basics of the algorithm that generates the same way that SCP:CB does.


SCP CB Generator.rbxl (67.1 KB)

It’s pretty barebones, so if you know what you’re doing and can script a little bit, you can 100% add in zones like Entrance, Light Containment, and Heavy Containment. I just wanted to provide a quick rundown of the system.

This is how the generation works, very simplified:

  1. You create a grid of your desired size, for this I chose 25x25 tiles
  2. Create the entrance tile right in the bottom-middle of the map (this is not required)
  3. Spawn a horizontal row of hallways that goes a random length, right above the entrance tile.
  4. From that horizontal row of hallways, generate a random amount of vertical hallways. Keep note that there must always be a vertical column of
    hallways on either the far left, or far right of the horizontal rows of hallways. This just ensures that the map is actually able to be completed. This
    vertical column of hallways must always be the max size up until the next row of horizontal hallways.
  5. From the last generated vertical column of hallways, repeat step 4 until you reach your desired amount of horizontal hallways.
  6. Spawn in rooms, these rooms will only spawn off hallways and deadends, converting whatever they spawned off of to be able to connect properly.

Example of a big map:

4 Likes

This looks really well-made and done! Good job!

Thank you, it took me pretty long to figure it out!!

and btw for step 5, i meant that you repeat step 3, not step 4

1 Like