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

Animation state machine (ASM)


Currently, our animation blending is a bit verbose and requires a lot of manual handling from Lua. Now, we're going to create a system that will manage animations and blends for us based on the concept of a finite state machine (FSM). We'll call this system an animation state machine but in essence, it's an FSM where states are animations and transitions between states represent the blend window, blend duration, and animation offsets.

States

Animation states in Lua will be represented by a table with a few key pieces of information. First, we need to store the animation, state name, whether the state is looping, and at what rate the animation will be played. The ASM will contain one animation state for each animation we support for our soldier.

Note

You can find the book's implementation of an animation state in the src/demo_framework/script/AnimationState.lua file.

Laying out the AnimationState class will create an initialization function which assigns default values...