Asteroid Defender by Galaxy117 (itch.io)
Space Invaders is an old classic 2D game where the objective is to destroy all of the enemy invaders at the top of the screen before you lose all of the available lives.
I decided to switch up the formula a bit when creating my own game in Unity, I decided it might be fun for the player to shoot falling asteroids that have varying speeds rather than a bunch of enemy ships that gradually make their way down the screen towards the player. add in some variation as to where the asteroids appear it will add some challenge.
Setup:
I started by creating a particle effect that I tweaked to create some flickering stars I thought it might add something different to the game rather than a static background. Then imported my created assets and started working on the scripts.
Scripting:
Player:
To Start I looked at player movement and getting my spaceship to move left and right across the screen at a set speed like the basic space invaders game. This would allow the player to move along the bottom of the game to shoot the falling asteroids that would be added later.

For Movement I needed 2 variables for speed and a transform. the transform is what will set movement across the x axis determined by the speed variable.
I also added into this script the variables to create a bullet when the spacebar is pressed. I used an If statement to check if the spacebar had been pressed and checks the fire rate variable (a value which determines the amount of time between shots). If these are okay a bullet will spawn from the ship to collide with the falling asteroids.
Shooting:
I then moved onto getting the player to shoot a bolt, this object doesn’t have to be in the game world and was placed in to start with so I could get a prefab object that can be called whenever the spacebar is pressed. The was given a rigid body 2D to give it weight and a box collider which, goes around the object and can detect when it collides with another object. Within the rigid body I set it to kinematic, so it isn’t affected by force or gravity, so bullets won’t start raining down on the player.

I created Variables for fire rate and projectile speed so the player can’t just hold the spacebar down to destroy all of the objects, it makes the game more challenging and enjoyable. For the speed I have set it up that once the asteroid is destroyed it will gradually gain speed, so it becomes harder and faster for the player to shoot.
I also added a line of code that destroys the bullets once they reach a specific height as it helps save on memory and means that asteroids won’t be destroyed before they are seen onscreen.
Asteroids:
The asteroids where relatively simple, like the bullet I created a prefab from my imported asset by placing the sprite into the game world and dragging it into project window. It was given a rigid body, so it reacts to gravity and physics and a box collider, so it detects when the bullet collides with the asteroid.

The Asteroid is set to randomly spawn between -9 and 9 on the x axis and start at on the y axis at 6. this means that when a steroid is destroyed or reaches the bottom (-6) it is destroyed and respawns at the top for the player to destroy again.
Final Product Before export:
FMOD:
Within FMOD I created 2 events that I used in my game. I created a laser sound that is player whenever the player shoots the projectile, there are 2 different sounds that can be played so there is some variation to make the game more interesting.
I then created an event for backing music. For this I wanted that if the Asteroids reached a certain point before, they were destroyed, the music would change to something more tense to alert the player to the situation.
Possible Improvements:
Whilst I am pleased with the final product, and I know I am still learning the software I feel that there are a few improvements I could add to the game to take it to the next level, these may get added at a later date beyond the deadline as a way of independently learning and experimenting with Unity.
Score and UI:
One of the main things I would like to add is the addition of a score and small user interface. This would mean the creation of a script and variables to give the player a score (for example 10) whenever they destroy an asteroid, the player could also loose points and have a value subtract from the score variable whenever they miss and asteroid and it reaches the bottom of the screen.
Other Objects:
I think the addition of an enemy ship that moves across the screen quite quickly might add another challenge to the game. I thought of this when playing a space invader style game online and noticed that sometimes a ship flies across the top of the screen and adds bonus points if it is destroyed.
Or maybe a bigger Asteroid that takes more than one hit to destroy or, it breaks into a few normal asteroids when it is hit. these where a few things I thought of that could possibly make the game a bit more enjoyable and challenging for the player.