O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Unity 2017 Game AI Programming - Third Edition

Book Description

Use Unity 2017 to create fun and unbelievable AI entities in your games with A*, Fuzzy logic and NavMesh

About This Book

  • Explore the brand-new Unity 2017 features that makes implementing Artificial Intelligence in your game easier than ever
  • Use fuzzy logic concepts in your AI decision-making to make your characters more engaging
  • Build exciting and richer games by mastering advanced Artificial Intelligence concepts such as Neural Networks

Who This Book Is For

This book is intended for Unity developers with a basic understanding of C# and the Unity editor. Whether you're looking to build your first game or are looking to expand your knowledge as a game programmer, you will find plenty of exciting information and examples of game AI in terms of concepts and implementation.

What You Will Learn

  • Understand the basic terminology and concepts in game AI
  • Explore advanced AI Concepts such as Neural Networks
  • Implement a basic finite state machine using state machine behaviors in Unity 2017
  • Create sensory systems for your AI and couple it with a Finite State Machine
  • Wok with Unity 2017's built-in NavMesh features in your game
  • Build believable and highly-efficient artificial flocks and crowds
  • Create a basic behavior tree to drive a character's actions

In Detail

Unity 2017 provides game and app developers with a variety of tools to implement Artificial Intelligence. 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 third edition with Unity will help you break down Artificial Intelligence into simple concepts to give you a fundamental understanding of the topic to build upon. Using a variety of examples, the book then takes those concepts and walks you through actual implementations designed to highlight key concepts, and features related to game AI in Unity 5. Further on you will learn to distinguish the state machine pattern and implement one of your own. This is followed by learning how to implement a basic sensory system for your AI agent and coupling it with a Finite State Machine (FSM).

Next you'll learn how to use Unity's built-in NavMesh feature and implement your own A* pathfinding system. You will then learn how to implement simple flocks and crowd's dynamics, key AI concepts. Moving on, you will learn how to implement a behavior tree through a game-focused example. Lastly, you'll combine fuzzy logic concepts with state machines and apply all the concepts in the book to build a simple tank game.

Style and approach

A self-explanatory practical guide with a series of tips and tricks on creating AI games with ease.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased 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.

Table of Contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  2. The Basics of AI in Games
    1. Creating the illusion of life
    2. Neural Networks
    3. Leveling up your game with AI
    4. Using AI in Unity
    5. Defining the agent
    6. Finite State Machines
    7. Seeing the world through our agent's eyes
    8. Path following and steering
      1. Dijkstra's algorithm
      2. Using A* Pathfinding
        1. IDA* Pathfinding
      3. Using Navigation Mesh
    9. Flocking and crowd dynamics
    10. Behavior trees
    11. Thinking with fuzzy logic
    12. Summary
  3. Finite State Machines and You
    1. Finding uses for FSMs
    2. Creating state machine behaviors
      1. Creating the AnimationController asset
      2. Layers and parameters
      3. The animation controller inspector
      4. Bringing behaviors into the picture
      5. Creating our very first state
      6. Transitioning between states
    3. Setting up our player tank
    4. Creating the enemy tank
      1. Choosing transitions
      2. Making the cogs turn
        1. Setting conditions
        2. Driving parameters via code
        3. Making our enemy tank move
        4. Testing
    5. Summary
  4. Implementing Sensors
    1. Basic sensory systems
      1. Cone of sight
      2. Hearing, feeling, and smelling using spheres
      3. Expanding AI through omniscience
      4. Getting creative with sensing
    2. Setting up the scene
    3. Setting up the player tank and aspect
      1. Implementing the player tank
      2. Implementing the Aspect class
    4. Creating an AI character
    5. Using the Sense class
    6. Giving a little perspective
    7. Touching is believing
    8. Testing the results
    9. Summary
  5. Finding Your Way
    1. Following a path
      1. The path script
      2. Using the path follower
      3. Avoiding obstacles
      4. Adding a custom layer
      5. Obstacle avoidance
    2. A* Pathfinding
      1. Revisiting the A* algorithm
      2. Implementation
        1. The Node class
        2. Establishing the priority queue
        3. Setting up our grid manager
        4. Diving into our A* implementation
        5. Implementing a TestCode class
        6. Testing it in the sample scene
        7. Testing all the components
      3. A* vs IDA*
    3. Navigation mesh
      1. Inspecting our map
      2. Navigation Static
      3. Baking the navigation mesh
      4. Using the NavMesh agent
      5. Setting a destination
      6. Making sense of Off Mesh Links
    4. Summary
  6. Flocks and Crowds
    1. Learning the origins of flocks
    2. Understanding the concepts behind flocks and crowds
    3. Using the Reynolds algorithm
      1. Implementing the FlockController
      2. The flock target
      3. The scene layout
    4. Using crowds
      1. Implementing a simple crowd simulation
      2. Using the CrowdAgent component
      3. Adding some fun obstacles
    5. Summary
  7. Behavior Trees
    1. Learning the basics of behavior trees
      1. Understanding different node types
        1. Defining composite nodes
        2. Understanding decorator nodes
        3. Describing the leaf node
    2. Evaluating the existing solutions
    3. Implementing a basic behavior tree framework
      1. Implementing a base Node class
      2. Extending nodes to selectors
      3. Moving on to sequences
      4. Implementing a decorator as an inverter
      5. Creating a generic action node
    4. Testing our framework
      1. Planning ahead
      2. Examining our scene setup
      3. Exploring the MathTree code
      4. Executing the test
    5. HomeRock card game example
      1. The scene setup
      2. The enemy state machine
      3. Testing the game
    6. Summary
  8. Using Fuzzy Logic to Make Your AI Seem Alive
    1. Defining fuzzy logic
      1. Picking fuzzy systems over binary systems
    2. Using fuzzy logic
      1. Implementing a simple fuzzy logic system
      2. Expanding the sets
      3. Defuzzifying the data
    3. Using the resulting crisp data
      1. Using a simpler approach
    4. The morality meter example
      1. The question and answer classes
      2. Managing the conversation
        1. Loading up the questions
        2. Handling user input
        3. Calculating the results
      3. Scene setup
      4. Testing the example
    5. Finding other uses for fuzzy logic
      1. Merging with other concepts
      2. Creating a truly unique experience
    6. Summary
  9. How It All Comes Together
    1. Setting up the rules
    2. Creating the towers
      1. Making the towers shoot
    3. Setting up the tank
      1. Bonus tank abilities
    4. Setting up the environment
    5. Testing the example
    6. Summary
  10. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think