For the final part of this portfolio assessment we've been asked to create a simple zombie game. In this text I will talk about the process of creation and link to the video of the finished product, then talk about the AI in detail with the use of some diagrams, and finish with conclusions.
While most of the work spent on this game was following the tutorials described in the four weeks up until the assessment, at the end we’ve been asked to add upon the base and make it ours. And so, my project used different assets then preferred. The base of the game is very similar – we have a set number of zombies roaming the area, and the player’s task is to survive as long as possible. The zombies have an AI system that I will talk about further into this text. The area is fairly small, composed of wide corridors and halls with walls and columns strewn about to give the player a chance to hide and to showcase AI’s pathfinding. Both the player and zombies have a set amount of health, and once it drops to zero either a zombie dies, or the game ends and we get our score and a chance to play again.
In addition to that, I added some non-AI extras such as the environment and lighting – the tutorial’s environment was very bare-bones, so I decided to spruce it up a little and make the atmosphere darker. This is why the game takes place in a closed, dark environment with only a few lights, adding some extra with the shadows. I also wanted the player to make sure how much life they have left, and so created the health bar.
Here is the video showcasing the game and the AI
AI in the project
In this project the main bit of AI is the zombies’ decision making, which is a fairly straightforward Finite State Machine which consists of 4 different states – Wandering, Chasing, Running, and Dead. While dead is fairly self-explanatory, and the machine doesn’t exit from it, others are more robust. For the wandering state there is a set of waypoints which the AI will shuffle and go through in that order. From that state, if it sees the player character there is an if statement. If the zombie has 50 health or less (so half or less) then it will switch to Running state, otherwise it will start Chasing.
When it’s Chasing it simply targets the player and runs towards them as long as they can see the player. Once they lose the sight of them or have 50 or less health points they will go back to Wandering. This basically means that once we leave the Chasing because of amount of health we will never visit it again. Running uses a function to find the waypoint which is the furthest from the zombie and run towards it, giving an illusion that the zombie is running away from the player. It will stop Running and start Wandering once two conditions are met – the zombie has to be out of the player’s range (which is just a variable, they have to be a certain distance away) and the timer, set to 3 seconds has to pass – this makes sure that the enemies will run for long enough to move outside of the player’s reach.
The AI that I created isn’t the top of the line. It is very simple, and sometimes has some hiccups but other than that it’s fast, and it could allow for many enemies to use it at the same time. I also ran short on time as other deadlines kept me pushing this one away, but I think that what I have created is at least presentable, if not decent. More could be done with the way the enemies either run away or look for the next waypoint, but I simply run out of time to do so and know it would work. On the other hand I’m happy with the non-AI extras that I added in the short amount of time, making sure that the game actually feels like a game and not a tiny demo showing off nothing new.
Here is the link to the Github repository of the game files.