lichess.org
Donate
Chaseddown

My first horror game

Off topic
First time making such a game. Here is how I did it.

I'll give a little walkthrough about how I started creating this game, so if you don't feel like reading all of it, here is the game. It is playable directly in the browser, but with nearly half the performance compared to the standalone version.

Somewhere around June or July, I started to watch those backrooms videos on YouTube and I was really intrigued by the concept. A month later I saw a video pop up where someone made a little algorithm in Unity that generates a somewhat similar disjointed maze, which I thought was really cool. So after following that tutorial and having the algorithm working, I thought of making it a little game around that. I did already know there were a lot of those type of backrooms games, but really none of them featured any randomly generated mazes, which would, of course, deliver a unique and way more exciting experience every time you would play.

After the core maze generation, I obviously wanted the player to be able to move. Now that the player has a way to navigate itself around the maze, it was time to add some objective to make the game fun and exciting to play, so I downloaded a model from Sketchfab that would represent the entity or simply the monster the player would be running away from. To make the entity be able to walk around the maze, I had to add a navigation system, but luckily Unity has built in features to easily control that. Because the maze differs in size and layout each time, the navigation should be baked (preprocessing all the data about the walkable areas for the entity once at the start, similar to caching data) at the time the maze itself is generated. Unfortunately the navigation system doesn't natively support baking at runtime, so I had to import a package that did exactly that.

After I got the entity to walk around the maze by setting its target position, it was time to give it a state machine, i.e. a way to react depending on its environment and start chasing the player around. The state machine works as follows:
The entity gets spawned within a certain amount of time, and after that it starts to search for the player, but when it does see the player it first starts to stare for a few seconds, and finally chases the player around until it either catches the player, where it is game over or where it gets too far out of reach of the player, disappears, and starts a timer to again get spawned in and search for the player. Every time the player manages to escape, the entity gets a little bit faster during the next chase until it hits a certain amount.

The maze still looked very plain with only those walls, so I added some different props, like pillars that will replace walls that are not surrounded by any others and arrows that have a small chance of spawning, just for some diversity in the maze. I still remember (somehow) being proud of this, but it was at least a start:

A little later on I also noticed that the wallpaper apparently was upside down.

Another thing with the maze generation was that it would completely freeze while it was generating the whole maze and instantiating each object and calculating a whole bunch of collisions. Therefore I rewrote the function a little bit so that it would asynchronously spawn all objects, with each frame spawning the desired amount of maze cells that the player indicated, depending on the processing power of the device. I also wrote a little script that culls out any objects that are out of the render distance, so that it wouldn't have to unnecessarily calculate all lights and meshes.

The game still looked a little plain and boring graphics wise, so I added a few post-processing layers to give the player a more enhanced and immersive experience of its surroundings, like chromatic aberration, lens distortion, film grain and most importantly a beautiful VHS-filter I found on GitHub. Additionally, I added a hand-held camera effect using Unity's Cinemachine package by overriding some values from that camera to the main camera. Because some people might not like some of these post-processing features, I made them adjustable in the settings, along with some other settings regarding graphics and audio. So the final result looked something more like this, which looks in my opinion a lot nicer:


In conclusion, I'm pretty proud of what I managed to make. The gameplay wasn't as exciting as I thought it would be after all, but it was very cool that every single object was completely generated at random. Plus it doesn't have to be considered a horror game, as you can choose the 'explore' mode where you can just run around for eternity in the maze without anything chasing you. And as I do own an Oculus quest 2 (with a nearly broken left controller), I decided to bring the core maze generation into a VR project, because everything feels way more realistic in VR and that really gives that enhanced experience. But I haven't really done much of that yet.