Nerd For Tech
Published in

Nerd For Tech

Let’s get backfire on our enemies

The next enemy type we will be adding into our game is 1 that knows when it is behind the player, it will shoot behind itself. To start, we will create a new game object for our enemy’s back lasers to be attached to and an offset for them so that they are fired off at the proper location:

From here, we can just create a copy of the enemy lasers and attach them to the script for the enemy. Next, we will create a new enemy type, like we did with the ramming enemy, and create it’s new methods:

In order for our enemy to know that if it is behind the player, we have to create our if statement where if the position of the enemy is lower than that of the player, we want it to shoot backwards. As we can see from the code, we have the lasers being pulled from a new script class, being EnemyLaser. After playing around with many different methods, and having little success with them, and for this moment I haven’t been able to get enough work on changing a script into a class and make it all work, I decided upon creating essentially a copy of the laser script, but change a few parts to make it suit the enemy laser. For now, it will be just set up for the back shot, but we could possibly use this new script to add in unique types of laser shots for just the enemy.
From here, we have to go into our newly created lasers and attach our new script to them, along with changing their ELaser. Once we have all of this set up, we can check to see if it works in our game:

Now that we have finally figured out how to get working back lasers, which took much longer than I had intended, we can adjust the switch statement for our enemy type spawn so that this new enemy type can come into play.
Next, we will look into adding in another new enemy type, and along with that creating a spawn rate adjuster so that we can pick which enemies we want to spawn at a higher rate.

--

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Recommended from Medium

Java 8 | Sorting Algorithm — Bubble Sort

Day 23/ Start Next Project : Final walkthrough

Introduction to NumPy in Python

What Is OpenAPI?

How to analyse a .phd heap dump from an IBM JVM

Visualization scraping website steampowered.com. How can I use it?

Kubernetes Horizontal Pod Autoscaling — for local development

Vedix Website Clone

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jordan Evans

Jordan Evans

More from Medium

For Loops | C#

Understanding Big O

Improving Upon Selection Highlighting in Our Game — Part 3

Branching out — Adding and switching branches in Git.