Unity 5.x Game AI Programming Cookbook - Jorge Palacios - E-Book

Unity 5.x Game AI Programming Cookbook E-Book

Jorge Palacios

0,0
39,59 €

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

Mehr erfahren.
Beschreibung

Build and customize a wide range of powerful Unity AI systems with over 70 hands-on recipes and techniques

About This Book

  • Empower your agent with decision making capabilities using advanced minimaxing and Negamaxing techniques
  • Discover how AI can be applied to a wide range of games to make them more interactive.
  • Instigate vision and hearing abilities in your agent through collider based and graph based systems

Who This Book Is For

This book is intended for those who already have a basic knowledge of Unity and are eager to get more tools under their belt to solve AI and gameplay-related problems.

What You Will Learn

  • Use techniques such as A*and A*mbush to empower your agents with path finding capabilities.
  • Create a representation of the world and make agents navigate it
  • Construct decision-making systems to make the agents take different actions
  • Make different agents coordinate actions and create the illusion of technical behavior
  • Simulate senses and apply them in an awareness system
  • Design and implement AI in board games such as Tic-Tac-Toe and Checkers
  • Implement efficient prediction mechanism in your agents with algorithms such as N-Gram predictor and naive Bayes classifier
  • Understand and analyze how the influence maps work.

In Detail

Unity 5 comes fully packaged with a toolbox of powerful features to help game and app developers create and implement powerful game AI. Leveraging these tools via Unity's API or built-in features allows limitless possibilities when it comes to creating your game's worlds and characters. This practical Cookbook covers both essential and niche techniques to help you be able to do that and more.

This Cookbook is engineered as your one-stop reference to take your game AI programming to the next level. Get to grips with the essential building blocks of working with an agent, programming movement and navigation in a game environment, and improving your agent's decision making and coordination mechanisms - all through hands-on examples using easily customizable techniques. Discover how to emulate vision and hearing capabilities for your agent, for natural and humanlike AI behaviour, and improve them with the help of graphs. Empower your AI with decision-making functions through programming simple board games such as Tic-Tac-Toe and Checkers, and orchestrate agent coordination to get your AIs working together as one.

Style and approach

This recipe-based guide will take you through implementing various AI algorithms. Each topic is explained and placed among other related techniques, sometimes building on the knowledge from previous chapters. There are also references to more technical books and papers, so you can dig deeper if you want to.

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

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 232

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

Unity 5.x Game AI Programming Cookbook
Credits
About the Author
About the Reviewers
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
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Behaviors – Intelligent Movement
Introduction
Creating the behavior template
Getting ready
How to do it...
How it works...
There's more...
See also
Pursuing and evading
Getting ready
How to do it...
How it works...
Arriving and leaving
Getting ready
How to do it...
How it works...
Facing objects
Getting ready
How to do it...
How it works...
Wandering around
Getting ready
How to do it...
How it works...
Following a path
Getting ready
How to do it...
How it works...
There's more...
Avoiding agents
Getting ready
How to do it...
How it works...
There's more
Avoiding walls
Getting ready
How to do it...
How it works...
There's more...
See also
Blending behaviors by weight
Getting ready
How to do it...
How it works...
There's more...
See also
Blending behaviors by priority
Getting ready
How to do it...
How it works...
There's more...
See also
Combining behaviors using a steering pipeline
Getting ready
How to do it...
How it works...
There's more...
See also
Shooting a projectile
Getting ready
How to do it...
How it works...
There's more...
See also
Predicting a projectile's landing spot
Getting ready
How to do it...
How it works...
There's more...
Targeting a projectile
Getting ready
How to do it...
How it works...
There's more...
Creating a jump system
Getting ready
How to do it...
How it works...
There is more
See Also
2. Navigation
Introduction
Representing the world with grids
Getting ready
How to do it...
How it works...
There's more...
See also
Representing the world with Dirichlet domains
Getting ready
How to do it...
How it works...
There's more...
See also
Representing the world with points of visibility
Getting ready
How to do it...
How it works...
There's more...
See also
Representing the world with a self-made navigation mesh
Getting ready
How to do it...
How it works...
Finding your way out of a maze with DFS
Getting ready
How to do it...
How it works...
There is more…
Finding the shortest path in a grid with BFS
Getting ready
How to do it...
How it works...
There is more…
See also
Finding the shortest path with Dijkstra
Getting ready
How to do it...
How it works...
There's more...
See also
Finding the best-promising path with A*
Getting ready
How to do it...
How it works...
There's more...
See also
Improving A* for memory: IDA*
Getting ready
How to do it…
How it works…
There is more…
Planning navigation in several frames: time-sliced search
Getting ready
How to do it...
How it works...
See also
Smoothing a path
Getting ready
How to do it…
How it works…
3. Decision Making
Introduction
Choosing through a decision tree
Getting ready
How to do it...
How it works...
There's more...
Working a finite-state machine
Getting ready
How to do it...
How it works...
There's more...
Improving FSMs: hierarchical finite-state machines
Getting ready
How to do it...
How it works...
See also
Combining FSMs and decision trees
Getting ready
How to do it...
How it works...
See also
Implementing behavior trees
Getting ready
How to do it...
How it works...
See also
Working with fuzzy logic
Getting ready
How to do it...
How it works...
There's more...
See also
Representing states with numerical values: Markov system
Getting ready
How to do it...
How it works...
See also
Making decisions with goal-oriented behaviors
Getting ready
How to do it...
How it works...
4. Coordination and Tactics
Introduction
Handling formations
Getting ready
How to do it…
How it works…
There is more…
See also
Extending A* for coordination: A*mbush
Getting ready
How to do it…
How it works…
There is more…
Creating good waypoints
Getting ready
How to do it…
How it works…
See also
Analyzing waypoints by height
Getting ready
How to do it…
How it works…
Analyzing waypoints by cover and visibility
Getting ready
How to do it…
How it works…
Exemplifying waypoints for decision making
Getting ready
How to do it…
How it works…
See also
Influence maps
Getting ready
How to do it…
How it works…
There is more…
See also
Improving influence with map flooding
Getting ready
How to do it…
How it works…
See also
Improving influence with convolution filters
Getting ready
How to do it…
How it works…
There is more…
See also
Building a fighting circle
Getting ready
How to do it…
How it works…
There is more…
See also
5. Agent Awareness
Introduction
The seeing function using a collider-based system
Getting ready
How to do it…
How it works…
The hearing function using a collider-based system
Getting ready
How to do it…
How it works…
There is more…
The smelling function using a collider-based system
Getting ready
How to do it…
How it works…
There is more…
The seeing function using a graph-based system
Getting ready
How to do it…
How it works…
The hearing function using a graph-based system
Getting ready
How to do it…
How it works…
There is more…
See also
The smelling function using a graph-based system
Getting ready
How to do it…
How it works…
See also
Creating awareness in a stealth game
Getting ready
How to do it…
How it works…
There is more…
See also
6. Board Games AI
Introduction
Working with the game-tree class
Getting ready…
How to do it…
How it works…
See also
Introducing Minimax
Getting ready…
How to do it…
How it works…
See also
Negamaxing
Getting ready…
How to do it…
How it works…
There's more…
See also
AB Negamaxing
Getting ready…
How to do it…
How it works…
See also
Negascouting
Getting ready…
How to do it…
How it works…
See also
Implementing a tic-tac-toe rival
Getting ready…
How to do it…
How it works…
There is more…
See also
Implementing a checkers rival
Getting ready…
How to do it…
How it works…
There is more…
7. Learning Techniques
.Introduction
Predicting actions with an N-Gram predictor
Getting ready…
How to do it…
How it works…
There is more…
Improving the predictor: Hierarchical N-Gram
Getting ready…
How to do it…
How it works…
Learning to use Naïve Bayes classifiers
Getting ready…
How to do it…
How it works…
Learning to use decision trees
Getting ready…
How to do it…
How it works…
See also
Learning to use reinforcement
Getting ready…
How to do it…
How it works…
Learning to use artificial neural networks
Getting ready…
How to do it…
How it works…
Creating emergent particles using a harmony search
Getting ready…
How to do it…
How it works…
8. Miscellaneous
Introduction
Handling random numbers better
Getting ready
How to do it…
There's more…
See also
Building an air-hockey rival
Getting ready
How to do it…
How it works…
See also
Devising a table-football competitor
Getting ready
How to do it…
How it works…
See also
Creating mazes procedurally
Getting ready
How to do it…
How it works...
There's more...
See also
Implementing a self-driving car
Getting ready
How to do it...
How it works...
See also
Managing race difficulty using a rubber-banding system
Getting ready
How to do it...
How it works…
Index

Unity 5.x Game AI Programming Cookbook

Unity 5.x Game AI Programming Cookbook

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 author, 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: 1230316

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78355-357-0

www.packtpub.com

Cover image by Andrés Rodolfo De León Mariola (<[email protected]>)

Credits

Author

Jorge Palacios

Reviewers

Jack Donovan

Lauren S. Ferro

Commissioning Editor

Akram Hussain

Acquisition Editors

Mohammad Rizvi

Usha Iyer

Content Development Editor

Kirti Patil

Technical Editor

Deepti Tuscano

Copy Editor

Angad Singh

Project Coordinator

Nidhi Joshi

Proofreader

Safis Editing

Indexer

Monica Ajmera Mehta

Production Coordinator

Arvindkumar Gupta

Cover Work

Arvindkumar Gupta

About the Author

Jorge Palacios is a software developer with seven years of professional experience. He has committed the last four years to game development working in various positions; from tool developer, to lead programmer. His main focus is AI and gameplay programming, and currently he works with Unity and HTML5. He's also a game development instructor, speaker, and game jam organizer.

You can find more about him on http://jorge.palacios.co

I'd like to dedicate this book to my parents; Betty and Elieser. They have given me all of their support for several years, and believed in me every step of the way. Words cannot express how grateful I am for having them in my life. This work is proof that dreams can be achieved when you turn them into goals.

Thanks to my partner in bits and codes, Christian Chomiak. His support and feedback is appreciated on every adventure, and every algorithm. Let's co-author the next book!

 

"If I have seen further it is by standing on the shoulder of Giants"

  --Isaac Newton

I'll always be grateful to Ricardo Monascal and Carlos Pérez. Their support, friendship and guidance allowed be to become a big deal of the developer I am today. I have seen further because of you.

I'm really happy to have Andrés De León's artwork as cover image.

Thanks to Ruchita Bhansali, Usha Iyer, Kirti Patil, Deepti Tuscano, and all the Packt team involved in this project. They are an awesome team to work with, and I cannot express how grateful I am for their patience and support along the way. I learned a lot from you and the whole process of ting and finishing a book. This book is your as much as it is mine.

About the Reviewers

Jack Donovan is a game developer and software engineer who has been working with the Unity3D engine since its third major release. He studied at Champlain College in Burlington, Vermont, where he received a BS in game programming.

Jack currently works at IrisVR, a virtual reality startup in New York City, where he is developing software that allows architects to generate virtual reality experiences from their CAD models. Before IrisVR, Jack worked on a small independent game team with fellow students, where he wrote the book, OUYA Game Development By Example.

Lauren S. Ferro is a gamification consultant and designer of games and game-like applications. She has worked, designed, consulted, and implemented strategies for a range of different purposes from the fields of professional development, recommendation systems, and educational games. She is an active researcher in the area of gamification, player profiling, and user-centered game design. She runs workshops for both the general public and companies that focus on designing user-centered games and game-like applications. She is also the developer of the game design resource Gamicards, which is a paper-prototyping tool for both games and game-like experiences.

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

When we think about artificial intelligence, a lot of topics may come to mind. From simple behaviors such as following or escaping from the player, through the classical Chess-rival AI, to state-of-the-art techniques in Machine Learning or procedural content generation.

Talking about Unity means talking about game development democratization. Thanks to its ease of use, fast-paced technological improvement, an ever-growing community of developers, and the new cloud services offered, Unity has become one of the most important game industry software.

With all that in mind, the main goal in writing this book is to offer you, the reader, both technical insight into Unity, following best practices and conventions, and theoretical knowledge that help you grasp artificial intelligence concepts and techniques, so you could get the best of both worlds for your own personal and professional development.

This cookbook will introduce you to the tools to build great AI; either for creating better enemies, polishing that final boss, or even building your own customized AI engine. It aims to be your one-stop reference for developing artificial intelligence techniques in Unity.

Welcome to an exciting journey that combines a variety of things that means a lot to me as a professional and human being; programming, game development, artificial intelligence, and sharing knowledge with other developers. I cannot stress how humbled and happy I am to be read by you right now, and grateful to the team at Packt for this formidable opportunity. I hope this material helps you not only take your Unity and artificial intelligence skills to new levels, but also deliver that feature that will engage players into your game.

What this book covers

Chapter 1, Behaviors – Intelligent Movement, explores some of the most interesting movement algorithms based on the steering behavior principles developed by Craig Reynolds along with work from Ian Millington. They act as a foundation for most of the AI used in advanced games and other algorithms that rely on movement, such as the family of path-finding algorithms.

Chapter 2, Navigation, explores path-finding algorithms for navigating complex scenarios. It will include some ways to represent the world using different kinds of graph structures, and several algorithms for finding a path, each aimed at different situations.

Chapter 3, Decision Making, shows the different decision-making techniques that are flexible enough to adapt to different types of games, and robust enough to let us build modular decision-making systems.

Chapter 4, Coordination and Tactics, deals with a number of different recipes for coordinating different agents as a whole organism, such as formations and techniques that allow us make tactical decisions based on graphs, such as waypoints and influence maps.

Chapter 5, Agent Awareness, deals with different approaches of simulating sense stimuli on an agent. We will learn how to use tools that we already know to create these simulations, colliders, and graphs.

Chapter 6, Board Games AI, explains a family of algorithms for developing board-game techniques to create artificial intelligence.

Chapter 7, Learning Techniques, explores the field of machine learning. It will give us a great head start in our endeavor to learn and apply machine-learning techniques to our games.

Chapter 8, Miscellaneous, introduces new techniques and uses algorithms that we have learned about in previous chapters in order to create new behaviors that don't quite fit in a definite category.

What you need for this book

The examples were tested and are provided using the latest version of Unity by the time of finishing this material, which is Unity 5.3.4f1. However, the book content started its development on Unity 5.1.2, so this is the minimum recommended version to work with.

Who this book is for

This book is aimed at those who already have basic knowledge of Unity and are eager to get more tools under their belt in order to solve AI and gameplay-related problems.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

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/Unity5xGameAIProgrammingCookbook_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. Behaviors – Intelligent Movement

In this chapter, we will develop AI algorithms for movement by covering the following recipes:

Creating the behaviors' templatePursuing and evadingArriving and leavingFacing objectsWandering aroundFollowing a pathAvoiding agentsAvoiding wallsBlending behaviors by weightBlending behaviors by priorityCombining behaviors using a steering pipelineShooting a projectilePredicting a projectile's landing spotTargeting a projectileCreating a jump system

Introduction

Unity has been one of the most popular game engines for quite a while now, and it's probably the de facto game development tool for indie developers, not only because of its business model, which has a low entry barrier, but also because of its robust project editor, year-by-year technological improvement, and most importantly, ease of use and an ever-growing community of developers around the globe.

Thanks to Unity's heavy lifting behind the scenes (rendering, physics, integration, and cross-platform deployment, just to name a few) it's possible for us to focus on creating the AI systems that will bring to life our games, creating great real-time experiences in the blink of an eye.

The goal of this book is to give you the tools to build great AI, for creating better enemies, polishing that final boss, or even building your own customized AI engine.

In this chapter, we will start by exploring some of the most interesting movement algorithms based on the steering behavior principles developed by Craig Reynolds, along with work from Ian Millington. These recipes are the stepping stones for most of the AI used in advanced games and other algorithms that rely on movement, such as the family of path-finding algorithms.

Pursuing and evading

Pursuing and evading are great behaviors to start with because they rely on the most basic behaviors and extend their functionality by predicting the target's next step.

Getting ready