Game Development Reference
In-Depth Information
The AI code is a lot to cover, and can be writen in a whole new topic, but we will learn how
to create a simple and easy way to make our AI look smart by using a simple method like the
random funcion instead of using search algorithm to get the possible move for the enemies.
It might not make our AI as smart as using those algorithms, but we will get the basic idea of
how to create the smart AI.
In this chapter, we will coninue from Project 5 , Creaing a Rocket Launcher , reuse the code
assets from the last chapter to implement the AI enemy. We will be creaing an enemy by
implemening the simple AI but smart enough to detect when to jump, run, walk, stop, or
shoot at the player by creaing the waypoint for the enemy to walk to each point, run towards
the player then shoot when the player gets closer, and jump when it detects the wall.
Mission briefing
We will be creaing an enemy that responds to our character. This enemy will be able to walk
from one point to another and check to see if the player is in shooing range, and he can
then shoot or run towards the player.
Finally, we will add the hit point bar to the player character and AI character as well as the
damage cost for the character weapon, which is the rocket from the last chapter.
What does it do?
We will start by adaping the old scripts from Project 5 , Creaing a Rocket Launcher , which
are New3PSController , RocketLauncher , and Rocket to be able to apply the hit
damage to the player or enemy.
Then, we will create the AIController script to control the enemy by adaping the
CharacterControl script from Project 4 , The Hero/Heroine Part II - Animaion and
Controls . In the CharacterControl script, we will use the Physics class to check if there
are any walls in front of the direcion in which the enemy is moving, so that it jumps over it.
Next, we will create the Waypoint script, which will control the AI moving towards
each waypoint posiion randomly or in an order. The Waypoint script will also use the
OnDrawGizmos() funcion, which will allow us to see the wireframe, ray cast line, icons,
and the area while we are playing in the game or ediing in the editor. This is very powerful
for debugging.
 
Search WWH ::




Custom Search