Phase I — Progress report — Enemy shooting and new player animations

Moving on from my previous quick guide articles, I’ll be providing some progress reports on the 2D space game I have been using in the examples. Where something is not covered by my previous articles I will create a quick guide. Today I have 3 changes to the 2D game.

Enemy Shooting

Previously the enemy did not provide much resistance outside of physically crashing in the player.

There is only strength in numbers here

To fix this I’ve added the ability for the enemy to shoot randomly with the minimum and maximum time editable in the inspector.

What we do in this script is assign a laser object to shoot, randomly set our next fire time using our minimum and maximum range, shoot and reset our timestamp again.

I have also edited the laser script to change its speed to a negative number if the laser is tagged as an enemy laser (this causes the laser to move down instead of up) and we add another check to our height before we destroy the laser (again assigning a negative value to our destruction height).

The player now has a collision check for enemy lasers (tags) and takes damage for a collision.

We create a new game object called enemy laser and on the laser script we ser the is enemy laser bool to true.

And we get our end result (I’ve adjusted shooting times for quicker shooting)


This is change is short, I’ve refactored the player thrusters so they now react to the input system events instead of using the new input systems version of “get key”.

The code has also been moved over to the thruster game object onto its own script. Part of my ongoing effort to tidy up the player script.

Player Animation — Banking

Using my newfound understanding of how to interact with the input system I’ve added in some animation for the player based on movement. Now the player has 2 animations for when they move left and right. The code will be refactored into an animation handling script later on.

A subtle change but one that makes the player movement much more interactive

That’s all for now.

Unity developer with a love of learning all things programming.