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

Avoidance


Avoidance steering behavior involves avoiding collisions between moving agents, objects, and other moving agents. The collision avoidance calculated from ForceToAvoidAgents creates a steering force in the tangent direction of a potential agent as two agents move closer to one another. Predictive movements are used to determine whether two agents will collide within a given amount of time.

Obstacle avoidance, on the other hand, approximates sandbox objects using spheres and uses the agent's predictive movement to create a steering force tangent for the potential collision.

Collision avoidance

To calculate the force to avoid other agents, based on the minimum time, to collide with other agents, we can use the ForceToAvoidAgents function.

local avoidAgentForce = 
    agent:ForceToAvoidAgents(minTimeToCollision);

Obstacle avoidance

A similar force to avoid other dynamic moving obstacles can be calculated using the ForceToAvoidObjects function.

local avoidObjectForce =     
    agent:ForceToAvoidObjects...