Warehouse War – Top-Down Shooter

The third game that I made for the Game Design and Prototyping module was Warehouse War, a top-down shooter game.

EXPLORATION OF IDEAS

With this project, I wanted to challenge myself to include elements that I had not included in my previous games, such as including a Game Over/Restart mechanic, manipulating the constraints of the Rigidbody component and also including audio in the game. I wanted to build on the experience that I had gained with Unity’s engine from the previous games made for the Game Design and Prototyping module to try out new challenges.

Thematically, I wanted the game to appear somewhat darker than the other games. I wanted the game to use human sprites instead of the classic, green zombie sprite to represent the trope of gangs of survivors that are seen throughout the apocalyptic zombie horror genre. I also knew that I wanted the area that the player is forced within to have a resemblance of a shipyard, which allowed for me to create two Cargo container tiles to act as cover to go alongside the Top Down Shooter asset pack by Kenney (Kenney, 2016).

Warehouse War

NEW FEATURES

One of the things that I wanted to achieve in this project was to implement elements that I had not included in Space Survival or Business Builder.

One of these elements was a way for the game to end. In my previous games, there was no method for the player to “die” – both games were intended to continue endlessly with no true way that the player could fail, whereas in this project I wanted the player to be challenged, forcing them to restart if they had collided with the enemy. I discovered a way to forcibly stop the player from moving through the manipulation of the Rigidbody component attached to the player’s sprite. When I looked into the Unity Documentation, I found that I could apply constraints to the Rigidbody component of the player by using RigidbodyConstraints.FreezePositionX and RigidbodyConstraints.FreezePositionY (Unity Technologies, 2014) in the player’s movement script, which would stop the player from moving horizontally and vertically upon this if statement being true.

I implemented this into the enemy collision if statement that was a part of the player’s movement script. This section of the script checked whether the objects that the player was colliding with had the game tag of “Enemy”, which upon being true, would display the game over screen, set their score counter to 0 and freeze their position.

With this, when the player eventually collides with the enemy units in the game, there is no escape; They must restart the entire game all over again as they can no longer move horizontally or vertically and their score counter has been reset, adding a challenge to the gameplay of how long can the player survive for when being chased.

A section of the Player’s movement script that triggers the game over screen, sets the players score counter to 0 and stops the player from moving upon collision with an enemy unit

As mentioned in the section above, I also created a restart button and game over text to appear upon the player colliding with an enemy unit. I did this by following a YouTube tutorial on how to create enemy collisions with the player and how to cause the player to die (Zotov, 2017c). The tutorial made use of Unity’s UI aspects and also taught me how to use scenes within Unity – such as calling on restarting a scene by using Unity’s SceneManagement when a certain condition is met or a UI element is triggered, such as the player dying and they press the restart button.

Once again, I used the YouTube tutorial “How to add a score counter into your Unity 2D game| Easy Unity 2D Tutorial” by Alexander Zotov that I used in my Space Invaders clone to include a score counter (Zotov, 2017a). This provides the game with an aspect of competition, to see how high the player’s score can go whilst surviving the enemy who is constantly chasing them.

I also knew that a feature that I wanted to include was for the camera to constantly track the player, giving me a larger space to work with. Using a Youtube Tutorial by Alexander Zotov, I was able to attach a script to the Main Camera in Unity that would constantly follow a target that I specified, which in this case was the player (Zotov, 2017b). This allowed for the player to move freely within the space without the gameplay being restricted to the static view of the overhead camera

The script that is attached to the Restart button, allowing the player to Restart upon an enemy collision.
This image has an empty alt attribute; its file name is image-5.png
Script attached to the Main Camera to constantly target the player’s character model.

I also made use of the bullet management that I had implemented into Space Survival. I found during my testing that if a bullet did not collide with an enemy, it would remain in the scene. This was not ideal as the game then had to keep the data for that bullet that missed, which could potentially cause problems during the gameplay.

I created an if statement as a part of the bullet behaviour script, which was to detect whether the bullet was colliding with any object that I had tagged as “Cover”. If this statement was true, the bullet was to be destroyed, which would improve the optimisation of the game.

If statement attached to the Bullet Behaviour script that destroyed bullets upon them colliding with cover

The bullet behaviour script also made use of an enemy prefab and instantiate to respawn the enemy units that was seen in Space Survival. The if statement detects whether the bullet is colliding with the tag “Enemy”, which if the statement is true, it would add 10 points to the score counter and would destroy the bullet and the enemy that was in the collision. Instantiate would then trigger and respawn the enemy within a declared space, allowing for a constant flow of enemies to chase the player.

The if statement in the Bullet Behaviour script that adds 10 point on the bullet colliding with an enemy unit and respawns the enemy within the declared space.

I also wanted to challenge myself in this project by using an audio track in the game to add an element of immersion and tension. I used the track “Dead Home” by SavannaMusic from Pixabay, a site that provides Royalty-Free music downloads and then lowered the pitch through FMOD. The audio asset was then attached to the camera and set to loop, as the track was only 36 seconds long and I wanted it to continue playing for as long as the player remained alive in the level.

SavannaMusic’s “Dead Home” in FMOD

CHALLENGES

As I was attempting to implement new elements into my game, I was also met with new challenges and errors that I needed to overcome.

One of these challenges was manipulating the constraints of the Rigidbody. Initially, using Rigidbody Constaints2D.FreezePositionX and RigidbodyConstaints2D.FreezePositionY did not work, as the Rigidbody that was already within my game and in my script was the 2D variation of Rigidbody, whereas the code that I was attempting to make work from the Unity Documentation was for its 3D counterpart. Once I realised what I had done, I changed the version of the Rigidbody Constraints that the code was calling on and the player successfully stopped when they collided with the enemy units.

Implementing RigidbodyConstaints2D.FreezePositionX|Y into the movement script to force the player to stop when colliding with an enemy

I also had issues with the Restart Button and the audio during this project, specifically when building the game itself. Within Unity’s game view, the game ran as expected – Music could be heard from when the game was running, the player gained score on an enemy kill and when the player eventually collided with the enemy, they were able to restart. Upon building, however, the game seemingly stopped functioning as it did within the game view. The audio would no longer play and the mechanic for restating the scene no longer worked, effectively ending the game as the player could no longer move due to the Rigidbody of the player constantly being frozen.

I had to remake the game entirely after being met with issues when opening the game itself – to find that the previous issues that I faced when building the game were fixed. The audio now played as expected and the respawning mechanic worked. This issue was incredibly confusing, as I had changed nothing as I remade the game – the scripts were attached to the respective pieces (E.G. scr_EnemyMovement is attached to the EnemyPrefab, scr_PlayerMovement attached to the Player), yet remaking the game fixed the aforementioned issue.

OUTCOME

Overall, I’m very pleased with how this game came out and how I managed to include elements that I had never touched on before. I feel more confident in using Unity now and using features that I had not used before, such as Scene Management, Audio and creating conditions such as what happens on a player’s death

I successfully created a mechanic for restarting the game through the manipulation of the Rigidbody component that was attached to the player model and collision detection with enemy units.

Warehouse War being played

Itch.io link to Warehouse War: https://rjusher.itch.io/warehouse-war

Referenced Material:

Kenney (2016) Kenney • Topdown Shooter. www.kenney.nl. Available online: https://www.kenney.nl/assets/topdown-shooter [Accessed 6 Nov. 2021].

Unity Technologies (2014) Unity – Scripting API: Rigidbody.constraints. docs.unity3d.com. Available online: https://docs.unity3d.com/ScriptReference/Rigidbody-constraints.html [Accessed 6 Nov. 2021].

Zotov, A. (2017a) How to add a score counter into your Unity 2D game| Easy Unity 2D Tutorial. www.youtube.com. Available online: https://www.youtube.com/watch?v=QbqnDbexrCw&list=LL&index=31&t=126s [Accessed 8 Nov. 2021].

Zotov, A. (2017b) How to make a main camera follow the character in Unity 2D game | The easiest Unity 2D tutorial. www.youtube.com. Available online: https://www.youtube.com/watch?v=K1XTWzHyCG0 [Accessed 8 Nov. 2021].

Zotov, A. (2017c) Making Unity 2D game. Make enemy collide with player and kill him | Simple UI Unity 2D tutorial. www.youtube.com. Available online: https://www.youtube.com/watch?v=JC59tDg4tmo&list=LL&index=24&t=374s [Accessed 7 Nov. 2021].