Book Image

Learning Game AI Programming with Lua

By : David Young
Book Image

Learning Game AI Programming with Lua

By: David Young

Overview of this book

Table of Contents (16 chapters)
Learning Game AI Programming with Lua
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with AI Sandbox
Index

Direct animation control


The first approach we'll implement is direct control over the ASM, as it is the simplest approach to understand and implement. While the agent has a lot of advantages as it knows exactly what animation is playing on its body, this technique tends to scale very poorly as more and more animation states are introduced. Although scaling becomes a problem, this approach allows for the lowest grain of control in terms of animation selection and response times from the agent.

As the agent must be responsible for animation selection, we'll create some basic actions that the agent can perform and represent as states:

DirectSoldierAgent.lua:

-- Supported soldier states.
local _soldierStates = {
    DEATH = "DEATH",
    FALLING = "FALLING",
    IDLE = "IDLE",
    MOVING = "MOVING",
    SHOOTING = "SHOOTING"
}

The death state

The first action we'll implement is the death state of the agent. As the ASM provides both a crouch and standing death variation, the action simply slows the...