๐”– Scriptorium
โœฆ   LIBER   โœฆ

๐Ÿ“

Learning Game AI Programming with Lua

โœ Scribed by David Young


Publisher
Packt Publishing
Year
2014
Tongue
English
Leaves
352
Category
Library

โฌ‡  Acquire This Volume

No coin nor oath required. For personal study only.

โœฆ Synopsis


Leverage the power of Lua programming to create game AI that focuses on motion, animation, and tactics

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.

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.

โœฆ Table of Contents


Cover
Copyright
Credits
About the Author
About the Reviewers
www.PacktPub.com
Table of Contents
Preface
Chapter 1: Getting Started with AI Sandbox
Introduction to AI sandbox
Understanding the sandbox
The project layout
The Premake build
Compiling the sandbox with Visual Studio 2008/2010/2012/2013
Open source libraries
Open source tools
Lua IDE โ€“ Decoda
Running AI sandbox inside Decoda
Setting up a new Decoda project
Debugging Lua scripts
Decoda Watch window
Decoda Call Stack window
The Decoda Virtual Machines window
Simultaneous Lua and C++ debugging
Visual Studio โ€“ Attach to Process
Decoda โ€“ Attach to Process
Decoda โ€“ Attach System Debugger
Associating Lua scripts from code with Decoda
The Lua virtual machine
The Lua stack
Lua primitives
Metatables
Metamethods
Userdata
C/C++ calling Lua functions
Lua calling C/C++ functions
Function binding
Creating custom userdata
Looking at the vector data type
The demo framework
Ogre
Object-Oriented Input System
SandboxApplication
Sandbox
Agent
Utility classes
Lua binding
Summary
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
Creating a floor
Adding a light
Adding a skybox
Adding meshes to the sandbox
Creating sandbox objects
Shooting blocks
Creating an agent Lua script
Creating a visual representation
Updating an agent position
Updating an agent orientation
Agent properties
Orientation
The forward axis
The left axis
The up axis
Location
Position
Size
Height
Radius
Physics
Mass
The max force
The max speed
Speed
Velocity
Knowledge
Target
Target radius
Path
Agents' movement
Mass
Speed
Velocity
Acceleration
Force
Agent-steering forces
Seeking
Applying steering forces to an agent
Clamping the horizontal speed of an agent
Creating a seeking agent
Pursuit
Fleeing
Evasion
Wandering
The target speed
Path following
Creating a path following agent
Avoidance
Collision avoidance
Obstacle avoidance
Avoiding blocks and agents
Group steering
Alignment
Cohesion
Separation
Creating a group of followers
Summing steering forces
Weighted sums
Priority-based forces
Summary
Chapter 3: Character Animations
Skeletons and meshes
Mesh skeletons
Loading an animated mesh
Showing a skeleton
Attaching meshes to bones
Attaching a weapon to our soldier
Animation clips
Playing an animation on our soldier
Soldier animations
Crouching animations
Standing animations
Weapon animations
Soldier poses
Weapon poses
Manipulating animations
Enabling and disabling animations
Looping animations
The animation length
The animation time
Normalized time
Restarting an animation
Playing a non-looping animation
The animation rate
Animation blending
Animation weights
Blend window
Blend curves
Linear blending
Playing with blend weights
Animation state machine (ASM)
States
Transitions
Creating animation state machines
Creating helper functions
Adding states
Adding transitions
Adding external helper functions
Forcefully setting states
Requesting states
Updating the animation state machine
Handling state transitions and state requests
Updating running animations
Adding functions to animation state machine instances
Building a weapon animation state machine
Building a soldier animation state machine
Updating animation state machines
Playing with states
Summary
Chapter 4: Mind Body Control
Creating a body
Creating a soldier
Attaching an animated mesh to an agent
Creating an obstacle course
Displaying the physics world
Adding callbacks to the animation state machine
Handling callbacks
endAdding callbacks to the ASM
Updating the ASM to call callbacks
Getting our soldier to shoot
The bone position
The bone rotation
Creating particle effects
The particle direction
Object removal
The collision impact callback
Shooting a projectile
Handling projectile collision impacts
Shooting
Getting our soldier to run
Setting a path through the obstacle course
Running the obstacle course
Creating a brain
Approaches for mind body control
Direct animation control
The death state
The idle state
The falling state
The moving state
The shooting state
A simple, finite state machine
Initializing the agent
Agent FSM state handling
Indirect animation control
The animation controller
Commands
The command queue
Manipulating commands
The change stance command
The die command
The fall command
The idle command
The move command
The shoot command
Assigning member functions
Initializing the controller
Adding handlers for commands
Updating the controller
Running the obstacle course
Creating a direct control agent
Creating an indirect control agent
Indirect control agent initialization
Indirect control agent update
Indirect control agent control
Spawning an indirect control agent
Action latency
Summary
Chapter 5: Navigation
Pathfinding
Creating a navigation mesh
Configuring navigation meshes
The walkable height
The walkable radius
The walkable climb height
The walkable slope angle
The minimum region area
Building the navigation mesh
Drawing the navigation mesh
Pathfinding on a navigation mesh
Path query
Query results
Random navigation points
The path information
Adding random pathfinding to our soldier
Updating agent paths
Drawing paths
Initializing the navmesh
Randomly running agents
Creating additional navigation meshes
Summary
Chapter 6: Decision Making
Creating userdata
Agent actions
Adding data members
Initializing an action
Updating an action
Action cleanup
Action member functions
Creating actions
The idle action
The die action
The reload action
The shoot action
The random move action
The move action
The flee action
The pursue action
Evaluators
Creating evaluators
Constant evaluators
Has ammo evaluator
Has critical health evaluator
Has enemy evaluator
Has move position evaluator
Is alive evaluator
Can shoot enemy evaluator
50/50 chance evaluator
Decision structures
Decision trees
Branches
Decision leaves
Branch evaluation
Building a decision tree
Creating branches
Creating a decision tree agent
Strengths of decision trees
Pitfalls of decision trees
Finite state machines
States
Transitions
Finite state machine structure
Helper functions
Adding states and transitions
Updating the finite state machine
Adding instance functions
Building a finite state machine
The idle state
The movement state
Random movement state
The shoot state
The flee state
The die state
The pursue state
The reload state
Creating a finite state machine agent
Strengths of finite state machines
Pitfalls of finite state machines
Behavior trees
The behavior tree node
Helper functions
Updating the behavior tree node
Actions
Conditions
Selectors
Sequences
Behavior tree
Behavior tree helper functions
Selector evaluation
Sequence evaluation
Node evaluation
Continue behavior tree evaluation
The behavior tree update loop
Updating the behavior tree
Building a behavior tree
The death behavior
The flee behavior
Combat behaviors
Reload behavior
The shoot behavior
The pursue behavior
The move behavior
The random move behavior
The idle behavior
Creating a behavior tree agent
Strengths of behavior trees
Pitfalls of behavior trees
Summary
Chapter 7: Knowledge Representation
Knowledge sources
Creating a knowledge source
Knowledge source evaluation
Blackboards
Creating a blackboard
Adding and removing knowledge sources
Evaluating knowledge sources
Setting and retrieving blackboard attributes
Blackboard member functions
Creating soldier knowledge sources
Enemy selection
Flee position selection
Constructing a soldier blackboard
Updating decision evaluators
Updating behavior actions
The die action
The flee action
The idle action
The move action
The pursue action
The reload action
The shoot action
Summary
Chapter 8: Perception
Events
Attributes
Sending events
Receiving events
Managing events
Assigning agent teams
Handling agent communications
Event types
Creating agent senses
Initializing senses
Updating senses
Agent visibility
Detecting other visible agents
Agent sighting events
New enemy sighted event
New dead enemy body sighted event
New dead teammate body sighted event
Handling new agent sightings
Intermittent agent sightings
Throttling agent visibility updates
Creating event handlers
Adding event handlers
Agent auditory senses
Auditory events
The BulletShot event
The BulletImpact event
Handling auditory events
Decaying blackboard events
Decaying auditory events
Team communications
The EnemySelection event
The PositionUpdate event
The RetreatPosition event
Updating agent behaviors
Enemy selection
Scoring dangerous positions
Score danger from bullet impacts
Score danger from bullet shots
Score danger from enemies
Score danger from dead bodies
Calculating the best flee position
Summary
Chapter 9: Tactics
Influence maps
The cell height
The cell width
Constructing an influence map
Configuration
Voxelizing a navigation mesh
Drawing influence maps
Accessing influences
Setting influences
Getting influences
Clearing influences
Spreading influences
Cell inertia
Cell falloff
Influence map layers
Updating the influence map
Soldier tactics
Initializing and updating tactics
Scoring team influences
Initializing team influences
Updating team influences
Configuring team influences
Scoring dangerous areas
Tapping into agent events
Adding event handlers
Initializing dangerous influences
Updating dangerous influences
Configuring team influences
Summary
Index


๐Ÿ“œ SIMILAR VOLUMES


Learning Game AI Programming with Lua
โœ David Young [David Young] ๐Ÿ“‚ Library ๐Ÿ“… 2014 ๐Ÿ› Packt Publishing ๐ŸŒ English

<span><p><b>Leverage the power of Lua programming to create game AI that focuses on motion, animation, and tactics</b></p><p><b>In Detail</b></p><p>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 be

Learning Game AI Programming with Lua
โœ Young, David ๐Ÿ“‚ Library ๐Ÿ“… 2014 ๐Ÿ› Packt Publishing ๐ŸŒ English

Cover; Copyright; Credits; About the Author; About the Reviewers; www.PacktPub.com; Table of Contents; Preface; Chapter 1: Getting Started with AI Sandbox; Introduction to AI sandbox; Understanding the sandbox; The project layout; The Premake build; Compiling the sandbox with Visual Studio 2008/2010

Learning Game AI Programming with Lua
โœ Young, David ๐Ÿ“‚ Library ๐Ÿ“… 2014 ๐Ÿ› Packt Publishing ๐ŸŒ English

Cover; Copyright; Credits; About the Author; About the Reviewers; www.PacktPub.com; Table of Contents; Preface; Chapter 1: Getting Started with AI Sandbox; Introduction to AI sandbox; Understanding the sandbox; The project layout; The Premake build; Compiling the sandbox with Visual Studio 2008/2010

Game Programming with Python, Lua and Ru
โœ Tom Gutschmidt ๐Ÿ“‚ Library ๐Ÿ“… 2003 ๐Ÿ› Course Technology PTR ๐ŸŒ English

Get ready to dive headfirst into the world of programming! "Game Programming with Python, Lua, and Ruby" offers an in-depth look at these three flexible languages as they relate to creating games. No matter what your skill level as a programmer, this book provides the guidance you need. Each languag