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 Wander


Here, we will define three states of AI. This will make it easier when specifying actions in different states. Now, the first state we will add is Wander. It will make the AI move randomly and indefinitely. This will be the initial state of the AI, and it will be capable of transitioning into other states once we approach the AI. The other two states are the two reactions that we give the AI. The idea is that when we approach the AI, there is a chance that it will flee or attack. The chance is the probability that we determined and created in the blueprint.

Setting up the project

Let's open Unreal Engine 4! Perform the following steps:

  1. First, we have to change our Enemy to act as a wandering frightened monster. So, double-click on the Enemy AIController. Now, navigate to Event Graph and zoom in.

  2. We want to create a new variable for State and make this Integer.

  3. Next, we have to change the Find Hero script. We will adapt this to detect the Hero. What we also want to keep is the chasing...