

Random DunGen - 2021
Random room generator demenstration with network compatability
This is a simple Unity demonstration.
In this demonstration you can see the work of my random room generator. It should work with any shaped room so long as you can determine it's shape with multiple box colliders. It can also work using Mirrors network library and each player will have the same dungeon or collection of rooms to explore. It works by using a bunch of prefabs within an array and randomly chooses one to place at an available door. Before it places the room it will get its dimensions from the colliders and makes a overlap boxes to determine if it will collide with anything. If it finds that there is room to place the room then it will, and so on and so forth until you get a randomly generated dungeon.
Self Analysis
Code analysis
Making a random room generator was an interesting task to tackle. Making a random room generator is actually very easy if you choose the grid approach but that limits you to the shape you chose to make the grid from.
However, what I did should allow you to make rooms from different shapes so long as you can use multiple box colliders to determine this shape.
This required a bit of a mathematical approach to it and I had that down quite easily. The issue I ended up facing was knowing how Unity dealt with it's GameObjects and Vectors. I found that I didn't know the correct functions to represent something from local to world space and that caused the objects to either be way off or with a slight offset therefore messing with the collision detection used to detect if a room is there already.
I found out I had to use Transform.TransformDirection to achieve this, The issue was that I was trying to just add the local space and the parents world space together to get the final result when I should have been reversing the matrices.
After this I had it all working, I had also previously put in basic networking into my project for the player but now I had to try and get it to work with my random room generation.
There are multiple ways to approach this, like seeds to define the random numbers used or pickling and unpickling suggested to me by my teacher where you make the dungeon on the server and then send it through to the clients. Pickling and unpickling is obviously not the preferred way of doing it since it takes more processing time, but for some reason the client would always lose it's random numbers when using a seed and therefore messing up the dungeon.
I couldn't find out why the numbers were just disappearing and because of that I opted to use the pickling technique. It could be possible that Mirror the Unity package that I used for networking might be using those numbers and that is why they are not available for the random dunGen.
This project has without question been very difficult to make, with problems popping up left and right and issues that are very hard to pin-point because they are in the back-end of Unity or Mirror's code and has therefore helped me greatly in learning how to pin-point issues and handle them effectively.
Screenshots

