Random "dungeon" generation

I was looking into random generation of structures for my game and this was the best thing I could find. That showcases fully random generation though.

So, how would I go about making a “dungeon” generator but with segments/pieces. For example: there would be a corridor piece that would be cloned and used whenever needed. There would be specific room pieces and (even better) ways to roughly control the generation (ex: only one of this room could spawn).

just make a folder of the models that you will use, Name them CORRECTLY and then just use this to randomly generate:

local DungeonParts = DungeonFolder:GetChildren()

local randomObj = math.random(1,#DungeonParts)
     --your code for creating the dungeon in here
      local Part = DungeonParts[i]
      local ClonedPart = Part:Clone

I know how to clone the segments, I’m mostly just asking about the random aspect: positioning the pieces correctly, rotating the pieces correctly, properly connecting rooms and corridors, etc.

Edit: And yes, I know how to use Random.new() or math.random()

1 Like

Just make it so that any direction would be able to use a corridor. Also that if there are more than a just copy the first bit of the corridor. @CrystalflxmeI made a rough drawing of how the corridor would look like:

image

Sorry I drew with my mouse so it is kinda bad…

For those who come to this thread for answers some time in the future:

I’ve been thinking about solutions to the segmented generation and I’m 99% sure that I’ve figured it out. Assuming every segment made has a bounding box, you can append attachments to each side of every structure to correctly position segments when attaching them to each other and that should solve position and rotation issues. At that point it would be up to picking a random number to see what structure should generate at each attachment.

Looks like I didn’t need the thread after all lol.

5 Likes

Well ya that is kind of what I was talking about… hopefully that fixes your problem. :smile: