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

Attaching meshes to bones


Attaching a mesh to a bone is exactly what it sounds like. Each time the animation updates the skeleton, the attached mesh is repositioned to stay in sync with the bone it is attached to. The sandbox provides an Animation.AttachToBone function that attaches a mesh to a bone and allows for a position and rotation offset from the bone.

Tip

Once a mesh has been attached to the bone, you should discard the variable to the mesh, as it is no longer valid. It is best to assign the variable to nil in order to avoid errors.

Attaching a weapon to our soldier

Attaching a weapon to our soldier is very easy with the Animation.AttachToBone function. Given the correct offset values, we can position a sniper rifle grip into the soldier's hand:

Sandbox.lua:

function Sandbox_Initialize(sandbox)

    ...

    local weapon = Core.CreateMesh(
        sandbox,
        "models/futuristic_soldier/" .. 
        "soldier_weapon.mesh");

    Animation.AttachToBone(
        soldier,
        "b_RightHand...