In the last section, we created the Waypoints
script and the Waypoints
object
, which will be used to limit the enemy movement and direction. In this section, we need to create the enemy game object, which will contain the waypoint and our AI character. We will use a prefab similar to that of the player character but remove some of it that is not necessary for the enemy.
We will start by creating the empty game object to contain the AI
and the Waypoints
object:
Enemy
. Then, assign its transform by clicking on this game object and go to the Inspector view to reset the transform to default, as follows:Waypoints
game object in the Hierarchy view that we created in the first section inside the Enemy
game object.AI
. Set the transform in the AI
game object as follows:AI
game object inside the Enemy
game object in the Hierarchy view, and then go to the Prefabs folder in the Project view. We will see the robot_AI
prefab object; drag it inside the AI
game object, which is a child of the Enemy
game object in the Hierarchy view similar to the Waypoints
game object, as shown in the following screenshot:We still need one more thing inside our AI
game object, which is the RocketLauncher
. This is basically a similar setup as for our player character; so go to the First Person Controller
game object, click on the arrow in front of it to bring down the Main Camera
, and then click on the arrow in front of the Main Camera
. We will see the RocketLauncher
game object, which we need for our enemy. Let's press Ctrl + D (in Windows) or Command + D (on a Mac) to duplicate it, and then drag this duplicate RocketLauncher game object inside the AI game object, as shown in the following screenshot:
If we take a look at the Hierarchy view of the AI
game and the Main Camera
game object, we will see a similar structure. The only difference is that the AI
game object has the AIController
script and CharacterController
attached to it as we can see in the preceding screenshot.
Then, we will click on RocketLauncher to bring up its Inspector view and set up the Transform and Rocket Launcher (Script) as follows:
SmokePosition
in the robot_AI
prefab, as shown in the following screenshot.)The last thing in this section—we will set up the position of our Enemy
game object, which is the parent of the AI
game object. So, let's click on the Enemy
game object and go to its transform position, and then set the following:
Now, we are done with this section. In the next section, we will create the script to control our enemy to be able to walk, run, jump, and shoot.
18.119.162.49