Unity from Proficiency to Mastery (Artificial Intelligence): Unity from Proficiency to Mastery, #1
()
About this ebook
Newly Edited and Updated Version
Master Artificial Intelligence with Unity
Without this book, most people spend too long trying to create NPCs (non-player characters) that behave like a real person the hard way. This book is the only one that will get you to create intelligent NPCs that can think and make decisions without wasting so much time. It includes six chapters that painlessly teach you the necessary skills to get started and master Artificial Intelligence with Unity and implement key AI techniques that you need to create entertaining games with believable and intelligent NPCs.
What you will learn
- After completing this book, you will be able to create more entertaining and fun games with intelligent and believable NPCs who can:
- Follow the player and avoid obstacles.
- Follow a specific path, or roam aimlessly.
- Detect the player through their senses (e.g., hearing, smell, visions).
- Make smart decision based on their state (e.g., health or ammos) to either attack the player, collect ammos and health packs, or flee.
- Set-up an ambush to capture the player.
- Act as a group (i.e., army) and follow the orders of the player or another NPC leader (e.g., attack the other team or withdraw from the battle)
Content of the book
The content of the book is as follows:
- Chapter 1 shows you how to create NPCs who can follow the player while avoiding obstacles or pre-defined areas (e.g., jump between platforms or avoid water).
- In Chapter 2 you will learn how to make your NPCs navigate the level by following set or random paths or wandering aimlessly.
- In Chapter 3 you will add senses to the NPCs so that they can detect the player and take smart decisions accordingly.
- In Chapter 4 you will make it possible for the NPCs to take more sensible decisions based on the environment and their own state. For example, NPCs may choose to refill ammunition rather than following the player, or they might decide to look for health packs when their health runs low.
- In Chapter 5 you will create two teams; one controlled by the player, and the other once controlled by another NPCs. These two teams will then engage in a battle and both the player and the NPC leader will be able to control their team asking them to attack or withdraw from the battle;
- Chapter 6 provides answers to frequently asked questions.
If you want to master Artificial Intelligence with Unity using a tried-and-tested method: download this book now!
Patrick Felicia
Patrick Felicia is a lecturer and researcher at Waterford Institute of Technology, where he teaches and supervises undergraduate and postgraduate students. He obtained his MSc in Multimedia Technology in 2003 and PhD in Computer Science in 2009 from University College Cork, Ireland. He has published several books and articles on the use of video games for educational purposes, including the Handbook of Research on Improving Learning and Motivation through Educational Games: Multidisciplinary Approaches (published by IGI), and Digital Games in Schools: a Handbook for Teachers, published by European Schoolnet. Patrick is also the Editor-in-chief of the International Journal of Game-Based Learning (IJGBL), and the Conference Director of the Irish Symposium on Game-Based Learning, a popular conference on games and learning organized throughout Ireland.
Read more from Patrick Felicia
Related to Unity from Proficiency to Mastery (Artificial Intelligence)
Titles in the series (1)
Unity from Proficiency to Mastery (Artificial Intelligence): Unity from Proficiency to Mastery, #1 Rating: 0 out of 5 stars0 ratings
Related ebooks
Godot from Zero to Proficiency (Foundations): Godot from Zero to Proficiency, #1 Rating: 5 out of 5 stars5/5Unreal Engine Game Development Cookbook Rating: 0 out of 5 stars0 ratingsGame Design Snacks: Easily Digestible Game Design Wisdom Rating: 0 out of 5 stars0 ratingsGame Design Essentials Rating: 2 out of 5 stars2/5Unity 5.x Game AI Programming Cookbook Rating: 0 out of 5 stars0 ratingsNGUI for Unity Rating: 0 out of 5 stars0 ratingsGame design Complete Self-Assessment Guide Rating: 0 out of 5 stars0 ratingsUnreal Development Kit Game Programming with UnrealScript Beginner's Guide Rating: 3 out of 5 stars3/5Unity from Zero to Proficiency (Beginner): Unity from Zero to Proficiency, #2 Rating: 5 out of 5 stars5/5Unity 3.x Game Development Essentials: Game development with C# and Javascript Rating: 0 out of 5 stars0 ratingsThink Like A Game Designer Rating: 4 out of 5 stars4/5GameMaker Essentials Rating: 0 out of 5 stars0 ratingsLearning Unreal® Engine iOS Game Development Rating: 0 out of 5 stars0 ratingsMastering Unity 2D Game Development - Second Edition Rating: 0 out of 5 stars0 ratingsLevel Up! The Guide to Great Video Game Design Rating: 4 out of 5 stars4/5Mastering iOS Game Development Rating: 0 out of 5 stars0 ratingsLÖVE for Lua Game Programming Rating: 5 out of 5 stars5/5GameSalad Essentials Rating: 0 out of 5 stars0 ratingsMastering Unity 5.x Rating: 0 out of 5 stars0 ratingsOpenGL Game Development By Example Rating: 0 out of 5 stars0 ratingsGodot from Zero to Proficiency (Intermediate): Godot from Zero to Proficiency, #3 Rating: 5 out of 5 stars5/5Unreal Engine 4 Scripting with C++ Cookbook Rating: 0 out of 5 stars0 ratingsPhaser III Game Prototyping Rating: 0 out of 5 stars0 ratingsSFML Game Development By Example Rating: 0 out of 5 stars0 ratingsUnreal Engine Physics Essentials Rating: 1 out of 5 stars1/5Building Levels in Unity Rating: 0 out of 5 stars0 ratingsUnity Virtual Reality Projects Rating: 0 out of 5 stars0 ratingsA Quick Guide to c# with Unity: Quick Guides, #1 Rating: 5 out of 5 stars5/5Getting Started with C++ Audio Programming for Game Development Rating: 0 out of 5 stars0 ratings
Programming For You
Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5Python QuickStart Guide: The Simplified Beginner's Guide to Python Programming Using Hands-On Projects and Real-World Applications Rating: 0 out of 5 stars0 ratingsPython: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 0 out of 5 stars0 ratingsExcel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/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 ratingsSQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5C++ Learn in 24 Hours Rating: 0 out of 5 stars0 ratingsSQL Guide for Microsoft Access: SQL Basics, Fundamental & Queries Exercise Rating: 5 out of 5 stars5/5
Reviews for Unity from Proficiency to Mastery (Artificial Intelligence)
0 ratings0 reviews
Book preview
Unity from Proficiency to Mastery (Artificial Intelligence) - Patrick Felicia
Patrick Felicia
Unity from Proficiency to Mastery
Artificial Intelligence
Copyright © 2017 Patrick Felicia
All rights reserved. No part of this book may be reproduced, stored in retrieval systems, or transmitted in any form or by any means, without the prior written permission of the publisher (Patrick Felicia), 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 expressed or implied. Neither the author and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
First published: July 2017
Published by Patrick Felicia
Credits
Author: Patrick Felicia
About the Author
Patrick Felicia is a lecturer and researcher at Waterford Institute of Technology, where he teaches and supervises undergraduate and postgraduate students. He obtained his MSc in Multimedia Technology in 2003 and his PhD in Computer Science in 2009, from University College Cork, Ireland. He has published several books and articles on the use of video games for educational purposes, including the Handbook of Research on Improving Learning and Motivation through Educational Games: Multidisciplinary Approaches (published by IGI), and Digital Games in Schools: a Handbook for Teachers, published by European Schoolnet. Patrick is also the Editor-in-chief of the International Journal of Game-Based Learning (IJGBL), and the Conference Director of the Irish Conference on Game-Based Learning, a popular conference on games and learning organized throughout Ireland.
Support and Resources for this Book
To complete the activities presented in this book you need to download the startup pack on the companion website; it consists of free resources that you will need to complete your projects, including bonus material that will help you along the way (e.g., cheat sheets, introductory videos, code samples, and much more).
Amongst other things, the resources for this book include:
All the C# scripts used in this book.
Cheat sheets with tips on how to use Unity.
3D characters and animation that you can use in Unity.
A library of over 40 tutorials (video or text).
To download these resources, please do the following:
Open the following link: http://learntocreategames.com/books/
Select this book ("Unity from Proficiency to Mastery: Artificial Intelligence").
On the new page, click on the link labelled "Book Files", or scroll down to the bottom of the page.
In the section called "Download your Free Resource Pack, enter your email address and your first name, and click on the button labeled
Yes, I want to receive my bonus pack".
After a few seconds, you should receive a link to your free start-up pack.
When you receive the link, you can download all the resources to your computer.
This book is dedicated to Helena
––––––––
[ ]
Table of Contents
1 Creating Simple AI with Built-in Characters
Setting up the environment
Simple AI (drag and drop) using Unity's built-in AI characters
Adding more obstacles
Grouping intelligent NPCs
Collision detection
Off-mesh links
Using areas and costs
Making it possible for NPCs to jump
Level Roundup
2 Creating Custom Navigation
Importing our 3D character
Specifying a target for the npc
Waypoints
Moving randomly within a path
Wandering navigation
Level Roundup
3 Simulating Senses
Setting-up the level
Building a new Animator Controller
Triggering the npc to change state from idle to patrol
Associating a movement to a state from the script
Adding Hearing
Adding Sight
Losing track of the player
Adding the sense of smell
Level Roundup
4 Behaviours and Decisions
Decisions based on internal values (health, ammos, etc.)
Providing weapons to the NPC
Ambushing
Adding a gun to the npc
Using dot products for a more accurate vision
Spawning NPCs
Fleeing
Level Roundup
5 Group Movements and Tactics
Walking behind the leader
Attacking several targets as a group
Withdrawing from a battle
Managing damage and attacks
Setting-up an intelligent team
Applying attacks to the NPCs
Level Roundup
6 Frequently Asked Questions
Navigation
Finite State Machines
Decision and senses
7 Thank you
Preface
After teaching Unity for over 5 years, I always thought it could be great to find a book that could get my students started with Unity in a few hours and that showed them how to master the core functionalities offered by this fantastic software.
Many of the books that I found were too short and did not provide enough details on the reasons behind the actions recommended and taken; other books were highly theoretical, and I found that they lacked practicality and that they would not get my students’ full attention. In addition, I often found that game development may be preferred by those with a programming background, but that people with an Arts background, even if they wanted to to know how to create games, often had to face the challenge of learning to code for the first time.
As a result, I started to consider a format that would cover both aspects: be approachable (even to the students with no programming background), keep students highly motivated and involved, using an interesting project, cover the core functionalities available in Unity to get started with game programming, provide answers to common questions, and also provide, if need be, a considerable amount of details for some topics.
I then created a book series entitled Unity from Zero to Proficiency that did just that. It gave readers the opportunity to discover Unity’s core features, especially those that would make it possible to create an interesting 3D game rapidly. After reading this book series, many readers emailed me to let me know how the book series helped them; however, they also mentioned that they wanted to be able to delve into specific features in more details.
This is the reason why I created this new book series entitled "Unity from Proficiency to Mastery"; it is for people who already have completed the four books in the series called Unity From Zero to Proficiency, and who would like to focus on a particular aspect of their game development.
In this book, focused on Artificial Intelligence, you will learn how to add and combine Artificial Intelligence features to make your game more challenging and the NPCs more believable. By completing each chapter, and by following step-by-step instructions, you will progressively create AI for your 3D games including: movement, decision making, senses, group movements and decisions, and a lot more.
[ ]
Content Covered by this Book
Chapter 1, Creating Simple AI with Built-in Characters, shows you how to create a simple AI for your 3D games with no coding involved; this includes NPCs that can detect and follow a particular target (including the player) individually or as a group, avoid obstacles, and jump over obstacles to reach their target. You will also learn how to apply the concept of navigation costs so that the NPCs can optimize their navigation.
Chapter 2, Creating Custom Navigation, shows you how to create different types of navigation for your NPCs, including set paths, random paths, and wandering aimlessly. Along the way, you will also learn how to configure an animated 3D character, and how to combine it with a Finite State Machine and a C# script to customize the navigation and animations.
Chapter 3, Simulating Senses, shows you how to add senses to the NPCs so that they can detect targets and take decisions accordingly. This will include adding the ability to hear, smell, or see the player and to start following the player accordingly. Along the way, you will also learn to configure a Finite State Machine in more details with parameters, transitions, multiple conditions for conditions, and different types of parameters (e.g., triggers, Boolean, integers, etc.)
Chapter 4, Behaviours and Decisions, shows how to make the NPCs smarter by making it possible for the NPCs to take more sensible decisions based on the environment and their own state; this will include: accounting for their health or weapons, and look for ammos or health packs accordingly when these are running low; you will also learn to create other interesting behaviours, often found in 3D games, such as fleeing from, or ambushing the player as well as sub-state machines, which are very useful when dealing with a group of actions for NPCs. Finally, you will learn how to make the sight of the NPCs more accurate using what is called dot products, and to also spawn NPCs at run time.
Chapter 5, Group Movements and Tactics, shows how to implement group behaviours for NPCs. You will learn how to create a group of NPCs that follow the orders of the player (e.g., follow the leader, attack targets or withdraw from the battle). You will also create a team of opponents that will be led by an intelligent NPC leader. Finally, you will be able to engage these two teams (i.e., your team and the opposing team) in a battle.
Chapter 6 provides answers to Frequently Asked Questions (FAQs) related to the topics covered in this book.
Chapter 7 summarizes the topics covered in this book and provides you with more information on the next steps.
What you Need to Use this Book
To complete the project presented in this book, you only need Unity 2018+ (or a more recent version) and to also ensure that your computer and its operating system comply with Unity’s requirements. Unity can be downloaded from the official website (http://www.unity3d.com/download), and before downloading it, you can check that your computer is up to scratch on the following page: http://www.unity3d.com/unity/system-requirements. At the time of writing this book, the following operating systems are supported by Unity for development: Windows XP (i.e., SP2+, 7 SP1+), Windows 8, and Mac OS X 10.6+. In terms of graphics card, most cards produced after 2004 should be suitable.
In terms of computer skills, all knowledge introduced in this book will assume no prior programming experience from the reader. So for now, you only need to be able to perform common computer tasks, such as downloading items, opening and saving files, be comfortable with dragging and dropping items and typing, and be relatively comfortable with Unity’s interface. This being said, because the focus of this book is on creating game AI, and while all chapters are explained step-by-step, you may need to be relatively comfortable with coding in C#, as well as creating and transforming objects.
So, if you would prefer to become more comfortable with Unity and C# programming prior to starting this book, you can download the books in the series called Unity From Zero to Proficiency (Foundations, Beginner, or Intermediate, Advanced). These books cover most of the shortcuts and views available in Unity, as well as how to perform common tasks in Unity, such as creating objects, transforming objects, importing assets, using navigation controllers, creating scripts or exporting the game to the web. They also explain how to code your game using C# along with good coding practices.
Who this Book is for
If you can answer yes to all these questions, then this book is for you:
Would you like to learn how to create AI (Artificial Intelligence) for your games?
Can you already code in C#?
Would you like to discover