Random map generation

It’s not your business to judge some random person’s game, and the game will have places where you can exit (aka, go to level 1) so it will have some sort of goal in the end.

And @Razorboots, is there a way to make certain items more rare (like have a rare wall that spawns that takes you to the manilla room or something)

Alright, after some testing, the lag is coming from the script checking each tile to see if it is occupied. The process is not very efficient, so my idea is to make the process more efficient by having the script only check the furthest out.

I turned up the render distance to around 40 and there is 0 lag if checking is paused.

Yep! I just updated the place file to support any number of tile types.
You can find and add new ones in ReplicatedStorage and also block 118 of the module script.

You can change the chance for an exit to spawn in line 33 of the module script. You could also add a method to check if there are any other exits that are too close nearby, but that would require having to loop through the entire chunk list again.

ChunkTutorial.rbxlx (63.6 KB)

Also, the checkForOverlappingChunk() method is, unfortunately, necessary for the generation to function properly.

Alrighty then, I think I’m gonna leave this topic off here then for now. Good luck!

3 Likes

This can help you for what you want to do

https://devforum.roblox.com/t/dungeon-generation-a-procedural-generation-guide/342413&ved=2ahUKEwiDyrL-sob3AhWjxIUKHZsrCoYQFnoECEMQAQ&usg=AOvVaw3C43GQ53Da3Sf1qVqlPkbc

The reason backrooms games work is because not only are you trying to find an exit, but you are also trying not to die, adding an aspect of realism (like camera bobbing or a running animation on a viewmodel) can immerse you in the experience and make it enjoyable even if you aren’t finding an exit.

Anyway back to the main point, I think the reason it might be lagging is because the remove function is checking the radial magnitude of the ending rooms while the add function seems to be in a double for loop (essentially searching the x and y distances separately). since the edges of the circle are being removed by the remove thing and added by the add thing every 0.2 seconds, that could be your issue.

(what i mean)


function gen.removeDistantChunks(x, z)
	-- Delete all the chunks which are too far away.
	for _, chunk in pairs(gen.chunkStorage) do
--right here check the x and y distances separately instead of grouping them together (i'm on a tablet so i can't format code lol)
		if (Vector2.new(chunk.PrimaryPart.Position.X, chunk.PrimaryPart.Position.Z) - Vector2.new(x, z)).Magnitude > (gen.renderDistance*gen.gridScale) then
			gen.removeChunk(chunk.PrimaryPart.Position.X, chunk.PrimaryPart.Position.Z)
		end
	end
end

edit: usually a simple distance check wouldn’t make any lag, accedentially deleting and cloning a bunch of instances would though, it also isn’t apparent in low render distances like 1-3 because the middle of the room isn’t being cut off by the edge of the circle radius

edit2: I’m really bad at explaining stuff by words so here’s a diagram

anything outside of the red circle is getting detected by remove checker and anything inside of the yellow square is being added, so all the blue area would be removed on the remove sweep and re-instanced on the rebuild sweep (causing a lot of a
lag)

Hey!

I generally understand this (amazing) script you’ve made, but could you just explain this line to me please?

local noise = math.noise( (posX + dividedX)/self.gridScale, (posZ + dividedZ)/self.gridScale, self.seed)

Thanks!

1 Like

How would I make it so that if the player goes in one direction, chunks behind them unload, then they go back the chunks are different?

(This is because memory isn’t really a thing in the backrooms)

that would be a lot more complicated as whenever the player leaves you would need to re-seed the plots. you can easily do it by some serverside unloading shenanigans

1 Like

you know this is clientsided, so there isn’t a way for entities i think.

I know I’m extremely late, but does anyone know how to fix an issue involving some of the floor tiles being missing?

Razorboots for some reason when i use this in my game it glitches out and doesnt work when i try to add more parts to it or change the texture