I’m working on a dungeon crawl and so far I have sort of procedural dungeons, here’s the basics:
- import models from Cinema4D - these are similar to morrowind/oblivion dungeon tiles
- add entrance and exit(s) in Unity - basically non-rendering spheres placed in the middle of the portal, oriented with the x-axis pointing in the direction of the portal (so for the entrance pointing into the room, for the exit, the x axis points out of the room)
- oh also these room pieces all start around 0,0,0 - and all face into the x-axis (except for the caps)
So using this I can make a long, snake like dungeon. Basically it chooses a random piece, aligns the new piece to the exit transform of the preceeding room (remember they’re all aligned the same, using 0,0,0). This part works great - I could have an exit at any angle/location (so far the portals are the same size). So downward corridors are no problem, I can also have multiple exits, though I haven’t coded for this yet.
Also I’ve started adding a few details, in this case, I have lights (little glowing crystals, with a light attached and my torch script for flickering). Now this might be a bit backwards, but for some things it will work: I place lights in every possible place I want them in each dungeon tile. Then there’s a despawn script that gives it a 1 in x chance to despawn on Awake. So any given room could have no lights (most likely), or multiple lights, including rare cases of larger lights. I can extend this to other details. Also I’ll create random spawn stuff as well.
So obviously there’s lots of work, but I can add in the multiple exit code, and basically add unused exits to a stack (the code currently caps the last room when maximum number of rooms is hit).
Here’s where I’m having conceptual issues - I’d like for more complicated mazes - currently I basically track how many right or left turns with a counter and make sure I don’t turn left or right more than once - but I’d like to be able to turn more than that, but also especially create loops with exits linked. I haven’t quite figured out how to do this, but have some ideas:
-
some scheme where by I check for bounding boxes being in the bounding boxes of existing meshes when I place my piece - (oh I should note I yield after creating each room to give the new room time to initialize) - I could remove an offending new room and try alternatives for a set number of tries before capping the room off and moving on to the next exit. This wouldn’t, however, really let me know what exits are capped by closing a loop - maybe some sort of collision of the actual exit spheres?
-
I was also thinking of tracking based on testing line segment intersections - basically between the entrance/midpoint and each exit/midpoint of every existing room - might get way slow after iterations, but also doesn’t solve the issue of whether exits are closed off.
-
do not try and close loops at all - just fudge it with prefabs that contain loops, just snake out from any additional exits - would limit complexity
Anyways the bit I have going so far actually looks very promising (heh had trouble sleeping last night as my mind was racing with possibilities). And of course there’s just the issue of monsters, combat code, inventory code, etc once I have the generator complete. The end idea should be a rogue like. I will create an entrance and an exit, and when you hit the exit it will generator a nastier next level (hopefully with slowly shifting tilesets as you go deeper).