XR Development

Pressure Cooker: Week 2

So we skipped week 1 because there wasn't really anything we did in development during the first week. is was basically all designing a concept and testing how it would play out. But getting back to my Individual conept.

Maze Generation

A very important part of my Maze game was generating a maze. The reason i wanted to generate this and not just make a maze out of manually placed parts replayability (that and not wanting to design a maze). By using the course mentioned in the designing section I was able to learn a bit more about maze generation algorithms.

Prim's algorithm:

Starting with prims algorithm: 'Prim's Algorithm is used to find the minimum spanning tree from a graph. Prim's algorithm finds the subset of edges that includes every vertex of the graph such that the sum of the weights of the edges can be minimized. Prim's algorithm starts with the single node and explore all the adjacent nodes with all the connecting edges at every step. The edges with the minimal weights causing no cycles in the graph got selected.'

Wilson's algorithm:

The next algorithm we looked at was Wilsons algorithm 'Wilson’s algorithm uses loop-erased random walks to generate a uniform spanning-tree — an unbiased sample of all possible spanning trees. Most other maze generation algorithms, such as Prim's, random traversal and randomized and randomized depth-first traversal, do not have this property.'

Recursive depth-first search (DFS) is an algorithm that traverses a graph in search of one or more goal nodes.

DFS was also the algorithm i stuck with in the end and the result looks something like the following.

Networking and Voice chat

Another important part of this concept was all about playing with other players! This meant i needed some kind of multiplayer. It was time to import Photon and Photon voice. I wont go into to much detail on photon considering it was a plugin, but it basically works with a lot of custom scripts and using the network callbacks that come with the plugin. After tweaking the project a bit and using the photon scripts i managed to get some multiplayer going which i first tested with a new scene only with a interactable cube.

We started playing arounds with the cube for a while just chilling and chatting.

Issues?

Having a procedural generated game brought on multiple problems that i hadent really thought about before hand, and being it multiplayer only made it more complex. To start off with when the game started (either by the host or a client) the game would generate a map, which meant every player would have a different maze. This wasnt a great thing because players were walking through walls (which turned out to be a corridoor in their own game). I eventually fixed this by checking if the person starting the game was the host, if so it would generate the maze, otherwise clients would only join.

This led to another problem being that clients werent able to see the maze because it was only instantiated on the host's game. after a while i found it was possible through photon to instantiate gameobjects over the network which fixed the problem.

The next one was building the navmesh (AI navigation terrain) on a procedurally generated gameobject. It turne out that it wasn't possible to predefine the navmesh on something that is instantiated at run-time. This meant i had to look through every maze piece after generation and rebuild the navmesh manually in a script. This brought another problem of my maze being 30 pieces wide and 30 deep. This meant that i had to rebuild 900 navmeshes which Unity did not like. AT ALL!

After a LONG time of trial and error (about 3 hours to be precise :D) i finally got it working. worst part was by accident which was cool that it worked, but less so that it took me so long and i didn't entirely understand why. So it turns out that I didn't need to loop through all of the maze pieces. Once the entire maze was generated i only needed to rebuild the navmesh for 1 piece of the maze and this automatically generated the navmesh on the entire maze.

Spiders! 😕

So i won't go too much into the spiders themselves as it wasn't my own creation, however it was time to make a AI controller that would make the spiders chase the players.

When the players would join the game they would be added to a player list and when a spider spawns into the maze it would receive a random target from the spawnlist. By using an NavAgent and the navmesh i was able to give the spiders a destination and they would move to their targets.

Now it was time to add a bit of atmosphere. First of all i made the scene dark, giving it a spooky vibe and added some fog (Pre built into the Universal Render pipeline). Only i found that the fog was making the scene too bright for what i wanted which made me take out the fog and just keep the darkness. All was left was to add the flashlights and spawn some weapons around the maze and players can traverse the maze in the dark, finding weapons that they could use to kill spiders with and find fellow players to wander with and talk to...

Last updated