- Home /
Randomly Generated Dungeons?
Hi, I'm pretty knew to programming and unity, but I was wondering if anyone can link me some reading material on how to randomly generate levels in unity. I eventually want to make a game where you get random missions, then walk into a portal and it takes you to a randomly generated dungeon with a boss at the end and chests loot, and enemies all the way in between. I don't plan on doing this anytime soon but would like to start reading up on it so some links on this subject would be very appreciated. Thanks.
Answer by Victov · Jun 01, 2012 at 03:12 PM
Try doing the same in 2d first. Level generation can be pretty tough, especially when you're new to programming.
You're probably going to want to do this tile-based. Make a grid of like 32x32 trough arrays. In a modelling program make different tiles, corner pieces, walls, etc etc. Then write a program that generates the dungeon and fills those arrays. You surely remember these kind of games from your childhood: Tile based 2d game this is exactly what you're going to want to do in 3d. The pipe would be an open area (where the player can walk) and the white would be walls.
Number your different pieces. Like:
corner piece - 1,
straight piece - 2,
dead end - 3,
dead end with loot chest - 4,
t-junction - 5,
well, you get it
then generate the 2dimentional array:
int[,] tiles = new int[32,32];
tiles[0] = {1,2,1,2,3,4,1,1,2,4,3,3,1,1,2,2,4,1};
tiles[1] = {2,1,1,2,3,4,2,3,3,2,3,3,1,2,2,2,4,1};
tiles[2] = {1,3,4,2,3,4,1,2,2,3,3,3,4,1,2,2,4,2};
of course you don't want this to be static, you want it to be dynamically generated.
Have fun with it... you said you weren't an experienced programmer...
Answer by Victov · Jun 01, 2012 at 01:42 PM
You're gonna want to use tiles. Try making it in 2d first, outside of unity. Since you're not an experienced programmer I really don't think this is gonna work, but here we go:
Make different models that fit seamlessly next to each other. A corner piece, a straight piece, a dead end... A bit like this.
Give each of your different pieces a unique ID, like this:
Corner piece
Straight piece
T-junction
Dead end
Dead end with loot
4-way junction
You get it by now...
Then make a multidimensional array, this example is static, you want to dynamicly randomly generate this.
int[,] tiles = new int[32,32];
tiles[0] = {1,2,1,2,3,1,1,2,3,1,1,2,2,3,2,1,2,3,1,3,2,2,3};
tiles[1] = {2,3,1,2,3,3,1,2,3,2,7,2,2,3,2,5,2,3,5,3,5,2,3};
tiles[2] = {3,1,2,2,3,1,4,2,3,5,1,2,3,3,2,1,2,3,1,3,2,4,3};
All the way down to 31, so that you have a 32x32 tile. (you can make it bigger ofcourse, you're only gonna need a better algorithm then). Look up these links for ideas and reading material: here, and take this!
this one is not in C# (unity is) but it does explain the basics of making a tile-based game very well. Very last link you're gonna get from me is this one, this is not about generating, nor is it about your type of game, but it has been so useful to me I had to just give you the link. The playlist is too short, there are more videos, just check his channel.
http://en.wikipedia.org/wiki/$$anonymous$$aze_generation_algorithm
Take a look at this algorithm too. It generates a maze randomly. $$anonymous$$aybe try doing a maze game first and then elaborate on the concept bringing it closer to the dungeon crawler you want it to be.
Your answer
Follow this Question
Related Questions
pre generated world 0 Answers
accessing variables from nearby gameobjects (Prim's Algorithm) 2 Answers
Minecraft strater package in JS 0 Answers
How can i make an infinite level? 4 Answers
Generate minecraft alike terrain 0 Answers