Portfolio 7 - Simple Game


Making a Simple Game

This week, we were tasked with turning our ongoing tutorial work into a somewhat functional game. The first thing I set about doing for this was borrowing some code I wrote for another project just so I could have a more comfortable camera and character controller- which is accomplished first by making the camera move in accordance with mouse movement, then having the player character move forward based on which direction the camera's facing rather than the direction the player object is facing, and finally, I made the character controller for the player operate more accurately in accordance with the world's gravity because I found the default character controller movement in Unity to be too floaty, both in the project the original code was from, and this tutorial project. You can also use the scroll wheel to zoom in and out to a certain degree, since it's mapped to the hovering distance of the camera.

Spawning Enemies and Player Health

Code for spawning enemies as well as player health was provided. The only real set up I had to do was link up a few events so that an enemy touching the player would decrease the player's health and on the player's health side, I had to link up a UI text element to track the player's health to the appropriate script, making a minor change to it so it could work with Unity's newer UI text system.

This is one of the two areas of the map that contain enemy spawners.

Below, you can see how the enemies that chase the player eventually catch up and destroy themselves upon running into the player, reducing their health which is displayed on-screen in wonderful aliased Comic Sans. You also see the player grab a health pickup, which increases their health by three points. The health pickup is relatively simple- I created a sort of old-fashioned doctor's bag model (textures from textures.com) and animated it in Unity to rotate around quickly by recording a few basic animation keyframes. It has a trigger script on it which accesses the player health script and increases it by a given amount.

Ending the Game

I modified the player health script to detect when the player has no health points left, which it does by checking the value, and if it's zero or less, it turns off the health tracking text, turns off the player model, and locks the camera in place. I didn't just outright disable the player object because it would stop the script from running, which I needed running so it could count down to when the game over screen is displayed. On the player's demise, the script also spawns in an explosion effect which I could have done with a particle system, but I thought it was funnier to use a stock explosion GIF (sourced from here) which always faces the camera (or "billboards"; I had to write a little code snippet so it would do this). The game can be restarted by clicking on the appropriate text on the game over screen, which uses a very simple line of code to reload the level.

Leave a comment

Log in with itch.io to leave a comment.