Reasoning:
The reason I am doing the horror game is mainly to experiment with enemy AI and with lighting. The reason I chose these two areas is that they are areas I have not really gone in-depth on.
My experience with lighting in Unity has never gone past the basic 2D scene lighting and point light, so in this, I hope to experiment with lighting cones and view cones. Following on from this, I will use the view cone to add to the enemy AI. enemy AI is an area I have also not really gone into, so this will give me a chance to go deeper.
For the enemy, most of my past enemy AI has been pretty simple s I only have really made simple chasing and shooting emeries. For this time around, I have two ideas in mind for ways to make them more complex.
The first one is to make the enemies chase the player until he gets out of range. If it gets out of range, the enemy will go invisible and speed up until in range again. This will make the enemy scarier as well as more complex. The other idea is to add a view cone, so the player can sneak on enemies, if the player sneaks on an enemy they can kill them without alerting the others.
First, I went to create and generate the maze for the game. I found a website where you can generate free mazes for my game. I started by editing some settings to create the layout I wanted. Furthermore, I then imported it into Unity to use as the guide for my level.
Here is the website I used to create the maze:
Next, after I imported the maze into Unity, I started to get an idea of the scale of the game. I used the green box as a guide for the player trying to find what the perfect screen scale would be. After a bit of tinkering, I got the size I felt right with and began working on adding a player.
For the player, I just added a circle, as I am not going for a graphically impressive game. For the level, I wanted a quick way to create the map without having to place each part by hand. To solve this, I ended up using a tile map, as it can allow me to draw out the map. I then traced along the generated maze until I had created the map.
As the goal is to get to the exit, I may change up the map after playtesting, but it is enough for now. I changed the background and added a cinemachine for the camera. This will give me access to features like camera follow for following the player and bounds for locking the camera into the level.
For the tile map, I made sure to add a collider, so the player could not move through walls. Here in the image, you can see the finished level as well as the collider on the object.
V
For the virtual camera, I set the following target for the player, as the game will be following the player's view. Next, I created a polygon collider to go across the level. I then added this to the confiner add-on for the camera.
For the next step in this project, I began working on the code for the player movement. I wrote some basic code that got the movement vectors and applied a force to the player. These allow him to have movement in all directions.
I make sure to add a limit to angled movements, as both vectors multiply together. I also added a line checking if the player is not moving to remove force so they stop.
Next, I wanted to work on the atmosphere of the game. The method I want to use to achieve this is to add a field of view to the player. For the look, I wanted to add a smaller light glowing from the player and a light cone emanating from the player.
To achieve this, I found a video by Code Monkey on creating this effect using the field of view. Here is the video I watched:
Field of View Effect in Unity (Line of Sight, View Cone)
To achieve this effect, I first need to make the player face the mouse, so the player can aim at the view cone. Unfortunately, this effect was not shown in the video I found, so I found a different video by Code Monkey on making this effect. Here is that video:
https://www.youtube.com/watch?v=fuGQFdhSPg4
Here is the code that aims the player at the position of the mouse. It works by getting the position of the mouse using a vector 3. Then it gets that position with the z and the camera. then in update we use vector three using the vectors from before and set an aim direction using them. Then it rotates the player based on the and using the aim direction.
Next, I decided to work on the code using the code monkey video on this topic. this code is complex, but it gets three triangles one for the position of the base then two more for the right and left points. This uses a view distance to decide how far the cone can go out from the base point. Then using the ray count you can smooth out the view angle by increasing this value. The cone appears in the game by using a mesh that takes in the parameters from the script. I then in unity set the variables and set the colour using a material.