Unreal Engine 4 AI Programming Essentials - Peter L. Newton - E-Book

Unreal Engine 4 AI Programming Essentials E-Book

Peter L. Newton

0,0
31,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Create responsive and intelligent game AI using Blueprints in Unreal Engine 4

About This Book

  • Understand and apply your Game AI better through various projects such as adding randomness and probability, and introducing movement
  • Configure and debug Game AI logic using multiple methodologies
  • Bridge the gap between your knowledge and Game AI in Unreal Engine 4

Who This Book Is For

This book is for programmers and artists who want to expand their knowledge of Game AI in relation to Unreal Engine 4. You are recommended to have some experience of exploring Unreal Engine 4 prior to this book because we jump straight into Game AI.

What You Will Learn

  • Understand the fundamental components of Game AI within Unreal Engine 4
  • Skillfully introduce Game AI within Unreal Engine 4
  • Configure, customize, and assign Navigation and AI components to your pawn
  • Create, debug, and analyze Game AI behavior
  • Design responsive Game AI using the Behavior Tree methodology
  • Create smart objects designed to interact with AI
  • Utilize advanced AI features within your project to maximize the user experience

In Detail

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.

Style and approach

This easy-to-follow project-based guide throws you directly into the excitement of Game AI in an approachable and comprehensive manner.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 191

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Unreal Engine 4 AI Programming Essentials
Credits
About the Authors
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Introduction to Game AI
Game Artificial Intelligence
How AI affects the gaming experience
Techniques and practices of game AI
Navigation
Achieving realistic movement with Steering
Creating a character with randomness and probability
Creating complex decision making with Behavior Tree
Root
Decorators
Composites
Services
Tasks
Blackboard
Sensory systems
Machine learning
Tracing
Influence Mapping
Unreal Engine 4 tools
Summary
2. Creating Basic AI
Goal
Setting up the project
Environment
Prerequisites
Using our new AIController class
Assigning the AIController class
Placing the pawn
Sending the instructions
Small tips on MoveToLocation
Reviewing the current progress
Adding the challenge
Traces
Reviewing the current progress
The Enemy logic
Adding the Enemy AI
Summary
3. Adding Randomness and Probability
Introducing probability
Probabilistic distribution
Non-uniform distribution
RandomStream in Unreal Engine 4
The plan
Adding Wander
Setting up the project
Creating probability
Non-uniform distribution with RandomStream
Creating transitions
Fleeing and attacking
Back to the action
The results!
Summary
4. Introducing Movement
Overview
Path Finding
The A* algorithm
Navigation Mesh
RecastNavMesh
The movement component
The AIController
Let's start!
Waypoints
Navigation
Navigation Modifiers
Back in the editor
The NavArea class
The navigation cost
Summary
5. Giving AI Choices
Behavior Tree in AIController
Creating Behavior Tree
Blackboard
Designing Behavior Tree
The Behavior Tree service
State transitions
Blackboard Compare Decorator
Environment Query System
Summary
6. How Does Our AI Sense?
Overview
AI Sense
AI Perception components
State machines
Pawn detection
State transition
Resetting the state
Simulating and playing
Summary
7. More Advanced Movement
Setting up the agents
Viewing the agent
Following the agent
Follow or lead
Steering behavior: Flocking
Flocking agents
Controlling behavior through UMG
A simple UI
Summary
8. Creating Patrol, Chase, and Attack AI
Creating a Blackboard
Mid-range attack
Controllers
Waypoints
BT Composites, Task, Decorator, and Service
Creating the logic
Summary
9. What Have We Learned?
Creating basic AI
The pros and cons of using controls
Adding randomness and probability
The pros and cons of using randomness
The pros and cons of using probability
Introducing movement
Giving our AI choice
The pros and cons of using EQS
The pros and cons of using Blueprint
How does our AI sense?
More advanced movement
Creating patrol, chase, and attack AI
The pros and cons of using Behavior Tree
The pros and cons of using blueprint for AI
Summary
Index

Unreal Engine 4 AI Programming Essentials

Unreal Engine 4 AI Programming Essentials

Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: March 2016

Production reference: 1110316

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78439-312-0

www.packtpub.com

Credits

Authors

Peter L. Newton

Jie Feng

Reviewer

Hamad A. Al-Hasan

Commissioning Editor

Edward Bowkett

Acquisition Editor

Larissa Pinto

Content Development Editor

Merint Thomas Mathew

Technical Editor

Dhiraj Chandanshive

Copy Editor

Shruti Iyer

Project Coordinator

Judie Jose

Proofreader

Safis Editing

Indexer

Tejal Daruwale Soni

Production Coordinator

Aparna Bhagat

Cover Work

Aparna Bhagat

About the Authors

Peter L. Newton gravitated toward computers at a young age. As his appetite for technology grew, web applications were his first exploration into development. The excitement of programming is what kept Peter diving further into different software designs and programming patterns. He is a self-taught programmer who has spent countless hours in reverse engineering assembly and arm instruction executables just for the joy of learning. Peter has several years of experience as a web developer, software developer, database architect, and hardware technician. His recent years were dedicated to the Virtual Reality/Gaming industry experience, working with such companies as Create, Sony Pictures, and the developers of Unreal Engine 4, Epic Games.

Peter's most recent VR project was Can You Walk The Walk?, which won Digital Hollywood's "Best In Virtual Reality Based on a Cinematic or Television Experience" award.

Thank you, readers, for your continued support in my AI adventures! I've created many tutorials, and because of your overwhelming response, I was reached out to by Epic Games, who requested my services as AI programmer. I've also made quite a few friends, such as Micheal Allar, Chance Ivey, Nick Whiting, Alexander Paschall, Yoeri, Jan, Pete, and many I'm likely to forget, and this is just to name a few. It has been an amazing few years! Living Epic!

Jie Feng is originally from Jiaxing, China. He is currently a PhD candidate at Columbia University, specializing in machine learning and computer vision. He has conducted research on problems ranging from detecting and recognizing objects in images and retrieving similar images from large-scale databases to understanding human behavior in videos. Jie's work has been published at top international conferences, and he has been granted a U.S. patent. He is also a software designer and developer and has worked at Microsoft, Amazon, and Adobe. Jie is passionate about applying Artificial Intelligence to real-world problems. His project using Microsoft Kinect to analyze motion for fitness has won People's Choice Award at Innovative Health Tech NYC competition, 2013. Jie is currently working on a fashion discovery product named EyeStyle.

Video games are the very thing that motivated him to study computer science. His favorite genre is action adventure. Titles including Resident Evil, Tomb Raider, and Uncharted inspire him in innovative thinking. This book is a unique experience for Jie to put his knowledge on Artificial Intelligence to game design and examine the potential of creating intelligent characters using Unreal Engine 4.

I would like to thank my parents for their unconditional love and support for my work and every decision I have made in my life. I feel lucky to have many talented people as my friends and colleagues, both in China and the U.S.. Last but not least, I want to express my appreciation to all game designers and developers out there for creating the fantasy world that inspires people and enriches their lives.

About the Reviewer

Hamad A. Al Hasan has a passion for games and game development and it has taken him far from the shores of Bahrain, where he graduated from Bahrain University in computer science. After working for a couple of years as software engineer, he jumped across the sea and the ocean to work as a gameplay programmer for Action Mobile Games in USA on their Infected Wars title. Hamad developed a passion for Unreal Engine, which then took him to Serbia at Digital Arrow and to Saudi Arabia as a consultant for Semanoor, the publisher of Trails of Ibn Battuta. After this, he worked as technical director for Empire Studios, a local game studio, in which he played a key role in establishing the studio as well as overseeing all the technical aspects of an unannounced mobile game.

Since 2010, Hamad has worked on a variety of systems, be it about player movements, camera and controls, Artificial Intelligence, networking and replication, weapons, different customizations, HUD, or Menus. He is equally familiar with Unreal Editor and its tools and has also developed a strong expertise in material and shader creation. Back in Bahrain, Hamad works on his own projects while continuing his freelance work.

You can contact him at http://www.alhasanstudio.com/.

www.PacktPub.com

eBooks, discount offers, and more

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

Artificial Intelligence (AI) is an essential part of any game. It makes the virtual world we create more immersive and fun to play in. Game AI is different from the general scientific AI that we know; it is more targeted to solve key problems in game design, including navigation, which is how a nonplayer character (NPC) should move from one point to another and avoid obstacles; decision making, which is how to perform certain actions based on different situations; and environment sensing, which is the ability to understand what exists in the environment and what its status is. These techniques make it possible to create a dynamic and realistic gameplay so that the players will be more engaged in the world that is created for them.

Game AI is complicated and brings a lot of challenges if you want to develop on your own. Unreal Engine 4 is a powerful game engine that provides rich functionalities to create cross-platform 3D and 2D games. It is well known for its advanced graphics and highly customizable components. Now, it is free to use and open source, which makes it one of the most popular game engines out there. Unreal Engine 4 comes with a complete suite of tools for game AI, including NavMesh, Behavior Trees, and Environment Query System. With these tools in hand, it is much easier to bring AI to your games. For game designers, you can even use a visual scripting tool called Blueprints to build your game logic, including AI, by just connecting nodes and without even writing a single line of code.

This book is our effort to introduce these wonderful tools in Unreal Engine 4 to build game AI to game creators who are interested in making their virtual world more interesting. It will cover all the components we have mentioned and show you how to use each tool to build different character behaviors and combine them to create more complex scenes.

We can't wait to see what you will create!

What this book covers

Chapter 1, Introduction to Game AI?, introduces the basic idea of AI and how it directly affects and enhances the gaming experience. You will learn the differences between the traditional and game-specific goals of AI.

Chapter 2, Creating Basic AI, helps you create your first AI step by step and talks about the techniques we will demonstrate along the way. We will dive right into Unreal Engine 4, using the bare components needed to create a single state with random movement for your AI.

Chapter 3, Adding Randomness and Probability, teaches you how to create random and probability techniques that can be used to add randomness, chance, and character to AI, which will make the game unpredictable and more interesting. We will cover how these are used within Unreal Engine 4.

Chapter 4, Introducing Movement, explains how to introduce movement to our AI characters within Unreal Engine 4. Path Finding will be used to allow our character to intelligently navigate within a level.

Chapter 5, Giving AI Choices, explains how to introduce autonomous behavior to our characters using Behavior Trees. Behavior Trees are a methodology that allows you to construct your AI logic visually in a tree structure and can be reused in different characters.

Chapter 6, How Does Our AI Sense?, explains how to use the different components available within Unreal Engine 4 to enable our AI to sense other AI and the pawns we will place within the world.

Chapter 7, More Advanced Movement, focuses on flocking and more advanced path-following behaviors. Flocking allows us to create group behaviors for several AI characters.

Chapter 8, Creating Patrol, Chase, and Attack AI, combines some of the components we used in the previous chapters, including AI Sense and Movement, to have our AI character navigate. Then, we will apply randomness to the time that the AI character will spend chasing after the characters it detects.

Chapter 9, What Have We Learned?, briefly glances over the previous chapters. We will also talk about additional examples of what we can achieve with these combined lessons.

What you need for this book

All you need is Unreal Engine 4.7.0, and you can download it from https://www.unrealengine.com.

Who this book is for

This book is for programmers and artists who want to expand their knowledge of game AI in relation to Unreal Engine 4. It is recommended that you have some experience of exploring Unreal Engine 4 prior to this book because we will jump straight into game AI.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Now, place a comment around this and name it Chase Hero."

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "If you're in Unreal Engine and you navigate to the Modes panel under Volumes, you'll see NavMeshBoundsVolume."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/LearningUnrealEngineAIProgramming_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Introduction to Game AI

This chapter will introduce the basic idea of Artificial Intelligence (AI) and how it directly affects and enhances the gaming experience. You will learn the differences between the traditional and also the game-specific goals of AI. We will introduce various techniques used in game AI, including navigation, Behavior Tree, sensor systems, and so on. You will learn in brief which tools we utilize for AI within Unreal Engine 4's editor. After this chapter, readers will gain a basic understanding of how AI can be applied to game development for a better gaming experience. The AI techniques that we will briefly cover here will be taught in the subsequent chapters.

Game Artificial Intelligence

When you first think of Artificial Intelligence, robots immediately come to mind. AI is derived from the idea of intelligence that helps living creatures make decisions. We take inputs, context, and our personal reasoning to decide on the actions we will perform. In AI, we try to virtually replicate this process to create systems that can have autonomous behavior. Assuming you have a fairly extensive gaming history, you would know that game AI is generally not smarter than some older games where your enemy may get stuck in a corner and fail to get out. Game AI now is by no means comparable to the general AI in scientific research. Game AI is designed to work in a well-controlled, predicable virtual world. It mainly consists of hardcoded rules to allow game actors to make proper actions corresponding to different situations. Game AI is meant to be fun, so it only needs to seem smart to the player within this context.

It is fair to say that AI is a very broad topic, so implementing every possible technique isn't the plan. So, it goes without saying that we will only cover what is necessary for you to create an awesome game AI. Keep in mind, though, that we will only touch on very specific game AI techniques; the world of AI is as vast as it is great.

How AI affects the gaming experience

Players seek a realistic and immersive experience in games. AI plays a huge part in forming this gaming experience by bringing realism and fun to the virtual world. Imagine that you are accompanied by a dog as you walk around or a flock of birds scatters when you make some noise. An enemy opponent is perhaps the most common and important implementation of game AI. The few types of game AI—navigating, fighting, assisting, or analytical—add the missing elements to other players to make them feel real and challenging to compete. This dates back to when it was used most notably in Chess, Nim, Pong, and Pac-Man. Up until now, it has been used in a war frame, with procedurally built levels. As the modern game design moves quickly by introducing new features to game play, such as the open world, massive in-game characters, and social interaction, it also introduces problems because these features cause AI decision making to require more input in unpredictable environments. Even now, AAA titles have their own complications with AI that result in poor user satisfaction. We will introduce in the following sections some powerful techniques to help create this important AI module and discuss how they are implemented in Unreal Engine.

Techniques and practices of game AI

There exist many techniques to cover different aspects in game AI, from fundamental movement to advanced environment sensing and decision making. Let's look at them one by one.

Navigation

Navigation for AI is usually built up of the following tools:

Navigation Mesh: Using tools such as Navigation Mesh, also known as NavMesh, you can designate areas in which AI can traverse. NavMesh is a simplified polygonal representation of a level (the green region in the following screenshot), where each polygon acts as a single node connected to its nearby ones. Usually, this process is automated and doesn't require designers to place nodes manually. Using special tools in Unreal, they analyze the geometry of the level and generate the most optimized Navigation Mesh accordingly. The purpose, of course, is to determine the playable areas in the level by the game agents. Note that this is the only path-finding technique available; we will use NavMesh in the examples provided in this book because it works well in this demonstration.Path Following (Path nodes): A similar solution to NavMesh, Path nodes can designate the space in which the AI traverses:Behavior Tree: Using Behavior Tree to influence your AI's next