Random Map Generation

I am currently working on a backrooms game and i got all main things done!


The only problem that i’m facing is how i should do map generation, because i want it to be random, but have an exit. Also players should be spawning random on the map. How would I approach this?

For the map generation I have no idea, but the game looks good! For player spawning make the generation script put a spawn point in every room or so. Good work!

1 Like

bleh that gives me motion sickness

I think I found the solution!

I’m going to explain this by using an image I made (Microsoft Paint).

  • Red: Wall (this placement is just an example)
  • Yellow: Plot Entrance/Exit
  • Pink: Map exit

Red: Wall (this placement is just an example)
Yellow: Plot Entrance/Exit
Pink: Map exit

A “plot” refers to everything within the black squares.

The plots will be randomly generated from existing rooms, each with four exits/entrances to prevent players from getting stuck.

As mentioned by owee814, every generated plot will have one spawn point so that players will spawn randomly on the map.

This is the idea I’m using. And now, it’s coding time!

(In a script)

local plots = require(script.Plots)

for x=0, 500, 50 do
	for y=0, 500, 50 do
		plots.Generate(x, y)

The “plots” variable refers to a ModuleScript in the script.


local plot = {}
plot.random = Random.new()

local rs = game:GetService("ReplicatedStorage")

function plot.GetRandom()
local possplots = rs:WaitForChild("PossiblePlots"):GetChildren()

	local randomplot = possplots[plot.random:NextInteger(1, #possplots)]
		return randomplot

function plot.Generate(x, y)
	local randomplot = plot.GetRandom()
	if x == 300 and y == 300 then
		randomplot = rs.ExitPlot
	local newplot = randomplot:Clone()
	local cframe = CFrame.new(x, 0, y) -- 0 is the y-level in the 3 space, change this if you want

	newplot.Parent = workspace:WaitForChild("GeneratedPlots")
	return newplot

return plot

Don’t forget to create the walls of the map!

If you have any questions, I’ll be happy to help!

End Result

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.