Setting the stage for intelligence with AI assets

With our Level and NavMesh now set up, we can return our focus to creating the enemy. First, we need to establish a Blueprint that will contain the enemy character. From your project directory in Content Browser, create a new folder called Enemy. Open this folder, then right-click on some empty space and select Blueprint Class. Open the All Classes group at the bottom of the popup and type ASP into the search bar. Select the Ue4ASP_Character object to create a new character Blueprint. We'll name this Blueprint EnemyCharacter.

Now that we have a Blueprint to contain our enemy character, we need to create three additional objects that will work together to manage the behavior of our enemy. The first of these is called Behavior Tree. A Behavior Tree is the source of the decision-making logic that will instruct our enemy on what conditions should cause it to perform which Actions. To create a Behavior Tree, right-click on the Enemy folder and then on the Artificial Intelligence category. Then, select Behavior Tree, and name it EnemyBehavior.

The second object we need to create is an AI Controller. The AI Controller will serve as a connection between the character and the Behavior Tree. It routes the information and Actions that are generated within the Behavior Tree to the character, which will enact those Actions. To create an AI Controller, right-click on the Enemy folder and click on Blueprint Class. Then, search for and select AIControllerand name it EnemyController.

The final object we'll create to control the behavior is called a Blackboard. A Blackboard is a container for all of the data that an AI controller needs in order to be governed by its Behavior Tree. To create a Blackboard, right-click on the Enemy folder and click on the Artificial Intelligence category. Then, select Blackboard. Predictably, we'll name this Blackboard EnemyBlackboard.

Next, we should make some modifications to EnemyCharacter. Because we created EnemyCharacter as an Ue4ASP_Character object type, it inherited information about the desired mesh, texture, and animations from the character created for the animation pack we imported. Some of this information, such as the mesh and support for the animations, is information we will want to keep. However, we need to ensure that EnemyCharacter knows how to be controlled by the right AI Controller. To change this, open the EnemyCharacter Blueprint now.

With EnemyCharacter open, look at the Components panel. Click on EnemyCharacter(self), which will be the top item in the Components list. Now, look at the Details panel and find the Pawn category. The last element of this category will be a drop-down list for AI Controller Class. Change the selection of this drop-down list to our new EnemyController.

While we're editing EnemyCharacter, we should change the color of the enemy as well. Currently, the Static Mesh shows a white humanoid that appears to be of the same style as that of the player's arms and gun. To better indicate to the player that the character is an enemy, we can change Static Mesh to use the same TargetRed Material we used for the Cylinders in the previous chapters. To do so, click on Mesh (Inherited) and find the Materials category in the Details panel. Change Element 0 of the Material to the TargetRed Material we created. You should see the humanoid character in Viewport change to a red color. Select CapsuleComponent (Inherited), check the Hidden in Game property in the Rendering category, and change Collision Presets to BlockAllDynamic. Compile and save it and return to the Level Editor. Drag the EnemyCharacter Blueprint onto the Level to create an instance of an enemy in our map. Rename the instance of EnemyCharacter in World Outliner to Enemy1.

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

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