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.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Unity 2017 Game AI Programming Third Edition
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  5. 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. Code in Action
      4. Conventions used
    4. Get in touch
      1. Reviews
  6. 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
  7. Finite State Machines and You
    1. Technical Requirements
    2. Finding uses for FSMs
    3. 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
    4. Setting up our player tank
    5. 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
    6. Summary
  8. Implementing Sensors
    1. Technical Requirements
    2. Basic sensory systems
      1. Cone of sight
      2. Hearing, feeling, and smelling using spheres
      3. Expanding AI through omniscience
      4. Getting creative with sensing
    3. Setting up the scene
    4. Setting up the player tank and aspect
      1. Implementing the player tank
      2. Implementing the Aspect class
    5. Creating an AI character
    6. Using the Sense class
    7. Giving a little perspective
    8. Touching is believing
    9. Testing the results
    10. Summary
  9. Finding Your Way
    1. Technical Requirements
    2. Following a path
      1. The path script
      2. Using the path follower
      3. Avoiding obstacles
      4. Adding a custom layer
      5. Obstacle avoidance
    3. 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*
    4. 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
    5. Summary
  10. Flocks and Crowds
    1. Technical Requirements
    2. Learning the origins of flocks
    3. Understanding the concepts behind flocks and crowds
    4. Using the Reynolds algorithm
      1. Implementing the FlockController
      2. The flock target
      3. The scene layout
    5. Using crowds
      1. Implementing a simple crowd simulation
      2. Using the CrowdAgent component
      3. Adding some fun obstacles
    6. Summary
  11. Behavior Trees
    1. Technical Requirements
    2. Learning the basics of behavior trees
      1. Understanding different node types
        1. Defining composite nodes
        2. Understanding decorator nodes
        3. Describing the leaf node
    3. Evaluating the existing solutions
    4. 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
    5. Testing our framework
      1. Planning ahead
      2. Examining our scene setup
      3. Exploring the MathTree code
      4. Executing the test
    6. HomeRock card game example
      1. The scene setup
      2. The enemy state machine
      3. Testing the game
    7. Summary
  12. Using Fuzzy Logic to Make Your AI Seem Alive
    1. Technical Requirements
    2. Defining fuzzy logic
      1. Picking fuzzy systems over binary systems
    3. Using fuzzy logic
      1. Implementing a simple fuzzy logic system
      2. Expanding the sets
      3. Defuzzifying the data
    4. Using the resulting crisp data
      1. Using a simpler approach
    5. 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
    6. Finding other uses for fuzzy logic
      1. Merging with other concepts
      2. Creating a truly unique experience
    7. Summary
  13. How It All Comes Together
    1. Technical Requirements
    2. Setting up the rules
    3. Creating the towers
      1. Making the towers shoot
    4. Setting up the tank
      1. Bonus tank abilities
    5. Setting up the environment
    6. Testing the example
    7. Summary
  14. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Unity 2017 Game AI Programming - Third Edition
  • Author(s): Ray Barrera, Aung Sithu Kyaw, Thet Naing Swe
  • Release date: January 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788477901