Hey, everybody! I’ve got a few simple questions regarding a project I’m sort of self-teaching myself. I’ll begin by explaining that everything I know about Unity is self-taught. I haven’t had any form of formal education regarding scripting or video game design. I’m working, at this moment, on a script or sort of “Master” entity that will take my map tiles and build off of them accordingly.
Here’s a preview of what my scene looks like when pulled apart.
The tileset is composed of hallway segments, intersections, and corners. Based upon the settings I give it, it’ll branch out, give the number of “splits” in a hallway, branch those out, and have a random chance to “turn” during each section.
This is a breakdown of my map after I’ve pressed Play.
Starting at the first Hallway Segment in the North-Western corner of the map, Floor Master will begin building South to begin the first Split. It counts the number of segments in a Hall. It’ll go out that far and roll a set chance to turn. Chance failed, it has created 0 out of 4 intersections so far, it placed an intersection. Flip a coin. Heads right, tails left. Tails. The hallway that branches to the West is now a dead end. It turns 2 out of 2 times and promptly ends in a locked door.
The East branch of Intersection 1 counts a new hallway and succeeds a random check to turn. Add turn 1 of 2. It adds a new Hall going South and fails the second check at the end. Placed 1 out of 4 intersections so far, placed an intersection. Flip a coin. Tails. The hallway that branches to the West is now a dead end. It turns 2 out of 2 times and promptly ends in a locked door.
The East branch of Intersection 2 adds a small hallway (due to random chance) and fails its first check to turn. Added 3 of 4 intersections so far, adding an intersection. Flip a coin. Tails. The Southern branch of Intersection 3 is now a dead end. It turns 1 of 2 times and promptly ends in a locked door.
The North branch of Intersection 3 adds a new hallway, succeeds to turn and adds Turn 1 of 2; Now going East. Another hallway is added and the check to add a new turn fails, Placed 3 of 4 intersections, adding the final intersection. Since it is the final intersection, both branches are dead ends. The North branch ends in a locked door after a single hallway. The South branch turns 1 of 2 times and ends in a locked door.
Here’s an overview of my inspector settings and what they look like.
Now begs my question and current conundrum. The maps are placing hallway segments inside of other hallway segments. The hallways are building themselves fine. Despite some larger maps building into one another, I’m impressed. It works exactly how I’ve coded it on the first try. Now, my initial thought would be to make incoming hallway segments travel up or down to go over or under existing hallway segments. This gives the illusion of multiple “Floors” in a level. However, I can’t think of any simple ways to detect the existence of a hallway segment by another hallway segment. At the moment, I have a Physics.OverlapSphere that detects if there’s more than one Hallway Segment in the area, but it won’t seem to work properly.
Can anybody else think of any ideas regarding object detection? How would I make these hallways avoid one another? Could I eventually add this to my rooms and make the hallway segments avoid rooms entirely as well? Is there a better way to do this? Discuss it with me!