Free Sample
+ Collection

Learning Game AI Programming with Lua

David Young

Leverage the power of Lua programming to create game AI that focuses on motion, animation, and tactics
RRP $26.99
RRP $44.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781783281336
Paperback352 pages

About This Book

  • Focus on programming game AI rather than handling low-level resource management
  • Bind Lua to build a script-based game AI using a C++ backend that provides hooks for graphics, physics, and resource handling
  • A tutorial-based approach where AI functionalities are layered piece by piece to create fully functional AI

Who This Book Is For

If you are a game developer or a general programmer who wishes to focus on programming systems and techniques to build your game AI without creating low-level interfaces in a game engine, then this book is for you.

Knowledge of C++ will come in handy to debug the entirety of the AI sandbox and expand on the features present within the book, but it is not required.

Table of Contents

Chapter 1: Getting Started with AI Sandbox
Introduction to AI sandbox
Chapter 2: Creating and Moving Agents
Creating a new sandbox project
Setting up the file structure
Extending the SandboxApplication class
Running your sandbox for the first time
Creating a new Decoda project
Configuring Decoda's run executable
Creating a sandbox Lua script
Shooting blocks
Creating an agent Lua script
Agent properties
Agents' movement
Agent-steering forces
Avoiding blocks and agents
Group steering
Creating a group of followers
Summing steering forces
Chapter 3: Character Animations
Skeletons and meshes
Attaching meshes to bones
Animation clips
Soldier poses
Manipulating animations
Animation blending
Animation state machine (ASM)
Building a weapon animation state machine
Building a soldier animation state machine
Updating animation state machines
Playing with states
Chapter 4: Mind Body Control
Creating a body
Adding callbacks to the animation state machine
Getting our soldier to shoot
Getting our soldier to run
Creating a brain
Direct animation control
A simple, finite state machine
Indirect animation control
Running the obstacle course
Action latency
Chapter 5: Navigation
Creating a navigation mesh
Pathfinding on a navigation mesh
The path information
Adding random pathfinding to our soldier
Creating additional navigation meshes
Chapter 6: Decision Making
Creating userdata
Agent actions
Creating actions
Creating evaluators
Decision structures
Decision trees
Building a decision tree
Creating a decision tree agent
Finite state machines
Building a finite state machine
Creating a finite state machine agent
Strengths of finite state machines
Pitfalls of finite state machines
Behavior trees
Creating a behavior tree object
Building a behavior tree
Creating a behavior tree agent
Strengths of behavior trees
Pitfalls of behavior trees
Chapter 7: Knowledge Representation
Knowledge sources
Creating soldier knowledge sources
Constructing a soldier blackboard
Updating decision evaluators
Updating behavior actions
Chapter 8: Perception
Managing events
Creating agent senses
Agent visibility
Agent sighting events
Handling new agent sightings
Agent auditory senses
Auditory events
Handling auditory events
Decaying blackboard events
Decaying auditory events
Team communications
Updating agent behaviors
Chapter 9: Tactics
Influence maps
Constructing an influence map
Drawing influence maps
Accessing influences
Clearing influences
Spreading influences
Influence map layers
Updating the influence map
Soldier tactics
Scoring team influences
Scoring dangerous areas

What You Will Learn

  • Create an animation state machine to drive AI animations within Lua
  • Build and find paths on navigation meshes
  • Write and debug Lua scripts within a full-scale Lua IDE
  • Develop decision logic with behavior trees, state machines, and decision trees to build modular, reusable AI
  • Manage short- and long-term knowledge representation with blackboard data structures
  • Add sensory perception to give AIs the ability to see and hear
  • Develop high-level tactics with multiple AIs based on influence maps

In Detail

Game AI can be easily broken up into a number of components such as decision making, animation handling, and tactics, but the balance and interaction between each system strikes a balance between good AI and bad AI.

Beginning with an introduction to the AI sandbox, each new aspect of game AI is introduced, implemented, and then expanded upon. Going forward, you will learn to utilize open source libraries such as Ogre3D, Bullet Physics, OpenSteer, Recast, Detour, and Lua to create an AI sandbox with an entire codebase available to expand and step through.

This is done through a step-by-step approach, from learning to move basic shapes to fully animating your soldiers. By the end of the book, your AI will be able to navigate, pathfind, manage animation playback, communicate, and perceive their environment.


Read More