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

Getting our soldier to shoot


Before we use the Soldier_Shoot helper function provided by the sandbox, we should implement our soldier shooting by hand. Overall, the process of shooting a bullet requires a look up of the bone position and rotation for the soldier, creating a physics representation for the bullet, attaching a particle system to the bullet, launching the profile, and then handling the impact of a bullet with any other physics simulated object.

The bone position

Getting a bone position requires passing a sandbox object or mesh to the Animation.GetBonePosition function. GetBonePosition also works for any attached object that contains bones as well. This allows you to retrieve the bone position of a bone within the weapon while it is attached to the soldier, for example:

local position =
    Animation.GetBonePosition(sandboxObject, boneName);

The bone rotation

Bone rotation is exactly the same as getting the bone's position, except that it returns a vector that represents the rotation...