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 4.x Game AI Programming

Book Description

Use your basic knowledge of Unity3D to add effective artificial intelligence to your games. This tutorial will take you through all the essentials, from flocking to pathfinding, from navigation graphs to behavior trees.

  • A practical guide with step-by-step instructions and example projects to learn Unity3D scripting
  • Learn pathfinding using A* algorithms as well as Unity3D pro features and navigation graphs
  • Implement finite state machines (FSMs), path following, and steering algorithms

In Detail

This book fills the gap between artificial intelligence (AI) books designed to learn underlying AI algorithms and general Unity3D books written to cover basic scene setup and scripting in Unity3D. Game AI Scripting in Unity3D covers implementing AI techniques such as flocking, pathfinding, path following, and behavior trees in Unity3D with example projects.

Game AI Scripting in Unity3D will show you how to apply AI techniques to your Unity3D projects using C# as the scripting language. Unlike other AI books and Unity3D books, this book tries to focus more on the application of AI techniques in the Unity3D engine, with sample projects that demonstrate finite state machines (FSMs), pathfinding, steering, navigation graphs, and behavior trees techniques.

This book shows how to implement various AI techniques in Unity3D by implementing the algorithm from scratch using C#, applying Unity3D built-in features, or using available scripts and plugins from the Unity Asset Store. For example, we’ll be implementing our own A* algorithm to do pathfinding but will also explore the Unity3D navigation graphs feature. Then we’ll use the Behave plugin to construct behavior trees for intelligent AI character behaviors.

Game AI Scripting in Unity3d covers other AI techniques such as flocking behavior, building a sensory system for taking inputs from the environment and other AI agents, and so on. In the final chapter this book will show you how to build a racing game AI project using Unity3D and applying the techniques described in earlier chapters.

Table of Contents

  1. Unity 4.x Game AI Programming
    1. Table of Contents
    2. Unity 4.x Game AI Programming
    3. Credits
    4. About the Authors
    5. About the Reviewer
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Introduction to AI
      1. Artificial Intelligence (AI)
      2. AI in games
      3. AI techniques
        1. Finite State Machines (FSM)
        2. Random and probability in AI
        3. The sensor system
          1. Polling
          2. The messaging system
        4. Flocking, swarming, and herding
        5. Path following and steering
        6. A* pathfinding
        7. A navigation mesh
        8. The behavior trees
        9. Locomotion
        10. Dijkstra's algorithm
      4. Summary
    9. 2. Finite State Machines
      1. The player's tank
        1. The PlayerTankController class
        2. Initialization
          1. Shooting bullet
          2. Controlling the tank
      2. The bullet class
      3. Setting up waypoints
      4. The abstract FSM class
      5. The enemy tank AI
        1. The patrol state
        2. The chase state
        3. The attack state
        4. The dead state
          1. Taking damage
      6. Using an FSM framework
        1. The AdvanceFSM class
        2. The FSMState class
        3. The state classes
          1. The PatrolState class
        4. The NPCTankController class
      7. Summary
    10. 3. Random and Probability
      1. Random
        1. Random class
          1. Simple random dice game
      2. Definition of probability
        1. Independent and related events
        2. Conditional probability
          1. A loaded dice
      3. Character personalities
      4. FSM with probability
      5. Dynamic AI
      6. Demo slot machine
        1. Random slot machine
        2. Weighted probability
          1. Near miss
      7. Summary
    11. 4. Implementing Sensors
      1. Basic sensory systems
      2. Scene setup
      3. Player tank and aspect
        1. Player tank
        2. Aspect
      4. AI character
        1. Sense
        2. Perspective
        3. Touch
      5. Testing
      6. Summary
    12. 5. Flocking
      1. Flocking from Unity's Island Demo
        1. Individual Behavior
        2. Controller
      2. Alternative implementation
        1. FlockController
      3. Summary
    13. 6. Path Following and Steering Behaviors
      1. Following a path
        1. Path script
        2. Path follower
      2. Avoiding obstacles
        1. Adding a custom layer
        2. Obstacle avoidance
      3. Summary
    14. 7. A* Pathfinding
      1. A* algorithm revisit
      2. Implementation
        1. Node
        2. PriorityQueue
        3. GridManager
        4. AStar
        5. TestCode class
      3. Scene setup
      4. Testing
      5. Summary
    15. 8. Navigation Mesh
      1. Introduction
      2. Setting up the map
        1. Navigation Static
        2. Baking the navigation mesh
        3. Nav Mesh Agent
          1. Updating agents' destinations
            1. The Target.cs class
      3. Scene with slope
      4. NavMeshLayers
      5. Off Mesh Links
        1. Generated Off Mesh Links
        2. Manual Off Mesh Links
      6. Summary
    16. 9. Behavior Trees
      1. Behave plugin
      2. Workflow
      3. Action
      4. Interfacing with the script
      5. Decorator
      6. Behave debugger
      7. Sequence
      8. Exploring Behave results
      9. Selector
      10. Priority selector
      11. Parallel
      12. Reference
      13. The Robots versus Aliens project
      14. Summary
    17. 10. Putting It All Together
      1. Scene setup
        1. Tags and layers
      2. Vehicles
        1. Player car controller
        2. AI Car Controller
        3. Finite State Machines (FSMs)
          1. Patrol state
          2. Chase state
          3. Attack state
      3. Weapons
        1. Gun
        2. Bullet
        3. Launcher
        4. Missile
      4. Summary
    18. Index