Unity 5.x Game AI Programming Cookbook
()
About this ebook
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 naïve 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.
Related to Unity 5.x Game AI Programming Cookbook
Related ebooks
Game Physics Cookbook Rating: 0 out of 5 stars0 ratingsUnity UI Cookbook Rating: 0 out of 5 stars0 ratingsUnreal Development Kit Game Design Cookbook Rating: 0 out of 5 stars0 ratingsUnity 5.x Shaders and Effects Cookbook Rating: 0 out of 5 stars0 ratingsUnreal Engine 4 Scripting with C++ Cookbook Rating: 0 out of 5 stars0 ratingsMaya Programming with Python Cookbook Rating: 5 out of 5 stars5/5Blender 2.5 Character Animation Cookbook Rating: 4 out of 5 stars4/5OpenGL Development Cookbook Rating: 5 out of 5 stars5/5Direct3D Rendering Cookbook Rating: 0 out of 5 stars0 ratingsUnity 5.x Animation Cookbook Rating: 0 out of 5 stars0 ratingsOpenGL 4 Shading Language Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsBlender Cycles: Lighting and Rendering Cookbook Rating: 0 out of 5 stars0 ratingsBlender Cycles: Materials and Textures Cookbook - Third Edition Rating: 0 out of 5 stars0 ratingsUnity Game Development Scripting Rating: 0 out of 5 stars0 ratingsUnity Game Development Blueprints Rating: 0 out of 5 stars0 ratingsUnity AI Programming Essentials Rating: 0 out of 5 stars0 ratingsPractical Game AI Programming Rating: 0 out of 5 stars0 ratingsMastering Unity Scripting Rating: 0 out of 5 stars0 ratingsBuilding Levels in Unity Rating: 0 out of 5 stars0 ratingsUnity Game Development Essentials Rating: 5 out of 5 stars5/5Procedural Content Generation for Unity Game Development Rating: 0 out of 5 stars0 ratingsUnity in Action: Multiplatform game development in C# Rating: 0 out of 5 stars0 ratingsUnity Animation Essentials Rating: 0 out of 5 stars0 ratingsGetting Started with Unity 5 Rating: 5 out of 5 stars5/5Building a Game with Unity and Blender Rating: 0 out of 5 stars0 ratingsExtending Unity with Editor Scripting Rating: 0 out of 5 stars0 ratingsUnity 4.x Game Development by Example Beginner's Guide Rating: 3 out of 5 stars3/5Creating ELearning Games with Unity Rating: 0 out of 5 stars0 ratingsA Beginner's Guide to Puzzle Games: Beginners' Guides, #3 Rating: 0 out of 5 stars0 ratingsUnity 5 Game Optimization Rating: 0 out of 5 stars0 ratings
Programming For You
Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5101 Amazing Nintendo NES Facts: Includes facts about the Famicom Rating: 4 out of 5 stars4/5Pokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards Rating: 0 out of 5 stars0 ratingsPython Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratings
Reviews for Unity 5.x Game AI Programming Cookbook
0 ratings0 reviews
Book preview
Unity 5.x Game AI Programming Cookbook - Palacios Jorge
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 (<andresvdlm@hotmail.com>)
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!
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
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 Packt
Copy and paste, print, and bookmark content
On 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