Requirements of the enemy controller

First of all, we need to move the enemy independently of the player input. As per our design, we want the enemy to continuously move left and right, but also slowly move down. Therefore, we can split the different movements between the two axes. For the x-axis, we can use a sine function to fluctuate (oscillate) between left and right continuously. For the y-axis, instead, we can have the usual movement, just much slower. For instance, the enemy spaceship can do two or three times left-right before it has moved down along the y-axis, a length similar to its dimension.

Another consideration is concerning when the enemy should shoot. In big games, there are complicated AI algorithms to perform a decision-making process. However, here we want to show how it's possible to create a challenging AI with just a few lines of code. So, in this case, we let the enemy shoot randomly, for instance, every one to three seconds. Later in the chapter, we will see a variation, where the enemy shoots when it is above the player.

Besides all of this, we have pretty much all the functionalities of the player controller, so the enemy spaceship moves, moving the rigidbody and implementing a Hit() function to take damage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset