Book Image

Unreal Engine 4 AI Programming Essentials

By : Jie Feng, Peter Newton
Book Image

Unreal Engine 4 AI Programming Essentials

By: Jie Feng, Peter Newton

Overview of this book

Unreal Engine is a powerful game development engine that provides rich functionalities to create 2D and 3D games. Developers have the opportunity to build cross-platform mobile and desktop games from scratch. This book will show you how to apply artificial intelligence (AI) techniques to your Unreal project using blueprints as your scripting language. You will start with an introduction to AI, and learn how it is applied to gaming. Then you'll jump right in and create a simple AI bot and apply basic behaviors to allow it to move randomly. As you progress, you'll find out how to implement randomness and probability traits. Using NavMesh, you will impart navigation components such as character movement, MoveTo nodes, settings, and world objects, and implement Behavior Trees. At the end of the book, you will troubleshoot any issues that might crop up while building the game.
Table of Contents (16 chapters)
Unreal Engine 4 AI Programming Essentials
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Adding the Enemy AI


Let's go back to Unreal Engine and focus on Content Browser. We now need an opponent. To add this, follow these steps:

  1. Right-click and select Blueprint.

  2. At the lower end of the window, let's drop all the classes and search for AIController.

  3. Select AIController under Controller and hit Select in the lower-right corner.

  4. We will name this AIController Enemy.

  5. Open Enemy AIController and go to the EventGraph section.

First, we must find Hero and then store it in a local variable to be used at any time. To do so, follow these steps:

  1. Right-click in an empty area within EventGraph and search for Event Begin Play.

  2. Pull from the exec pin and search for Get All Actors Of Class.

  3. Set the Actor Class pin to Hero.

  4. Pull from the Out Actors array and search for ForEachLoopWithBreak:

We want a filter for the Hero class within the MyCharacter pawn returned. To do so, follow these steps:

  1. Pull from the Array Element pin and search for Cast to MyCharacter.

  2. Then, pull from the As My Character pin and search...