Creating a spawning enemy part 1
So, I went to try and figure out what type of enemy would be unique that isn’t a threat to you from the start, but if you take too long to kill it, you will be swarmed with enemy units. This was a lot more complicated to do in practice, as for a few of the different methods that I used, I would just get a constant waterfall effect of enemies:
Sure, this may look nice, and would be quite the challenge to deal with, but the issue becomes the game will crash after a few seconds because the enemies are spawning infinitely. So, I had to go back to work trying to figure out how to get this issue fixed. I tried a bunch of different methods, all to no avail. So, the next step was to ask the community I’m a part of with GameDevHQ and see if someone there could help figure out this issue. Sometimes getting another pair of eyes on things helps solve problems that come up.
So, after getting some help to figure things out we managed to work it out. To start, we need to create a couple new variables to work with:
From here, we are going to create a couple new voids to work with:
Our first void is just our basic new enemy type void. We however need to set the last part so that our Spawner uses our SetSmallEnemy void when it instantiates the new enemy type. We have this SetSmallEnemy type in place so that we can have these small enemies not spawn as a spawner themselves and possibly cause a waterfall glitch on our screen again.
As for the SetNormalEnemy, this is our new method that we will attach into our spawn manager script so that it knows when we want to instantiate the enemy, it pulls from the full range, rather than our shorted list from the smallenemy void.
Next, we will have to go into our Spawnmanager script to add this quick line of code into the enemy spawner:
Now that we have all of this in place, we can take a look to see how it works in our game:
Well, we can see that our spawner now spawns just 1 enemy at a time, but now there is a new weird bug that we need to figure out. As we can see with the red enemies, which are supposed to dodge our lasers, have decided that they want to change their colour, but forget how to dodge us.
As for how to fix this, I will get back to tinkering with the code and write a second part for this feature.