O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

//does not exceed the maximum force available to this vehicle, just
//add together. Otherwise add as much of the ForceToAdd vector as
//possible without going over the max.
if (MagnitudeToAdd < MagnitudeRemaining)
{
RunningTot += ForceToAdd;
}
else
{
//add it to the steering force
RunningTot += (Vec2DNormalize(ForceToAdd) * MagnitudeRemaining);
}
return true;
}
Prioritized Dithering
In his paper, Reynolds suggests a method of force combination he calls pri-
oritized dithering. When used, this method checks to see if the first priority
behavior is going to be evaluated this simulation step, dependent on a pre-
set probability. If it is and the result is non-zero, the method returns the
calculated force and no other active behaviors are considered. If the result
is zero or if that behavior has been skipped over due to its probability of
being evaluated, the next priority behavior is considered and so on, for all
the active behaviors. This is a little snippet of code to help you understand
the concept:
SVector2D SteeringBehaviors::CalculateDithered()
{
//reset the steering force
m_vSteeringForce.Zero();
//the behavior probabilities
const double prWallAvoidance = 0.9;
const double prObstacleAvoidance = 0.9;
const double prSeparation = 0.8;
const double prAlignment = 0.5;
const double prCohesion = 0.5;
const double prWander = 0.8;
if (On(wall_avoidance) && RandFloat() > prWallAvoidance)
{
m_vSteeringForce = WallAvoidance(m_pVehicle->World()->Walls()) *
m_dWeightWallAvoidance / prWallAvoidance;
if (!m_vSteeringForce.IsZero())
{
m_vSteeringForce.Truncate(m_pVehicle->MaxForce());
return m_vSteeringForce;
How to Create Autonomously Moving Game Agents
| 123
Combining Steering Behaviors

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required