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

Fleeing and attacking


So, we will take from our old bit and add a small change, which will make the character run away from the Target instead of towards it. This will basically demonstrate the probability that you can give your AI reactions to various stimuli. Perform the following:

  1. We will get our State variable. Then, we want to subtract 1 from this, getting a 0 or 1 index. Next, we want to create a Select node and plug the results of the subtraction into the node.

  2. From there, we want Option 0 to be 1 and Option 1 to be -1. This will make the character either Run or Flee from Target. Now, zoom in to the Get Direction Vector node.

  3. Let's multiply Return Value by the Get Direction Vector node results. You must first convert Int to Float. Then, multiply this by the vector. Then, pull the vector back into Make Rot from X:

Back to the action

Let's focus back on Enemy EventGraph at the bottom. We want to implement a way for our AI to wander. Perform the following steps:

  1. Start by searching for Get...