Top Down Shooter Prototype

For my Top Down Shooter prototype, I wanted to explore the mechanics of Unity further whilst creating a fun and addictive game.

In my PlayerMovement script, I had to reference the camera in order to access ScreenToWorldPoint. This converts a point from the screen space to the world space. This, coupled with the built in Input.mousePosition, is invaluable when scripting for Unity games as it allows the mouse to be used in gameplay, whether its for a first person shooter to aim, or a top down shooter.

Atan2 is a very useful built in mathematical function. It returns the angle between a 2D vector and the x-axis. This is another example of the usefulness of Mathf and its functions that make maths related coding and logic in Unity quick and efficient. However, one downside of this function specifically is that you have to put the y-coordinate first. This is quite confusing and could easily cause problems with someone’s code, especially since in Unity the game will break with just one error.

The code that is commented out is used to restrict the player’s movement so they cannot move off of the screen. This was a challenge as, unlike the Space Invaders game, the player can move anywhere across the screen. The code works, however, I wanted to refine it further.

This CheckBoundaries function controls all of the boundaries around the screen. Three variables are passed through it in the FixedUpdate function, which controls where the boundary is. If neither of the if statement conditions are met, the function just returns the movement, allowing them to move.

In the PlayerShooting script, I have used Input.GetButtonDown(“Fire1”). Unity’s built in functions are one of its best features, with this one being no different. It allowed me to quickly assign shooting to the left click of a mouse. This was achieved by calling the Shoot function inside of it.

In the Shoot function, I have created a RigidBody2D component and assigned it to itself so it does not have to be manually dragged in via Unity. RigidBody2D allows the object to react to real time physics in the game.

I have also created a game object called bullet and instantiated it with the bullet prefab and spawn location.

I have assigned the bullet spawn location to an empty object that is at the tip of the gun. The bullet prefab is assigned to the prefab of the bullet I created – allowing each bullet to have the same properties.

In the EnemyMovement script, at the start of the game the player and enemy’s RigidBody2D component is assigned to itself, as well as the player itself being assigned as the player sprite. This is so the enemy knows what to move towards when the game starts.

When the enemy collides with the player, their health decreases. The tag system in Unity is by far one of my favourites. It allowed me to specify what each game object is and how it interacts with another game object with a different tag.

The Bullet script controls how the bullets interact with the enemy and where the enemy respawns. It was difficult to come up with a solution for the enemy to respawn both above and below the screen, to make it more realistic. However, I came to the conclusion to create two separate prefabs for the enemies. Two of the starting enemies are tagged with “Enemy”, whereas the other two starting zombies are tagged with “Enemy2”. Enemy and Enemy 2 have different respawn locations, Enemy is at the bottom of the screen whilst Enemy2 is at the top. To achieve this I also needed to create separate respawn prefabs too.

To improve my prototype, I could give Enemy2 different characteristics such as it being slower but it takes two hits to kill. This would add another dynamic to my game and make it even more engaging.

I created the PlayerHealth and GameOver scripts using the knowledge I learnt through extra research on my Space Invaders project. The code is practically the same, however, I assigned the players health to a value of one this time. I did this to create a more tense and unforgiving experience. I believe it fits well with the fast paced nature of the game.

However, this could be seen as a negative as if the player had more health, I could implement a health gaining power up when breaking open crates. This would be an improvement on the game as a single game would last longer, potentially allowing for different enemy types to spawn if you survive long enough.

LINK TO MY GAME : https://ethanconyers.itch.io/top-down-shooter

Leave a Reply

Your email address will not be published. Required fields are marked *