Game Development Reference
In-Depth Information
Applying steering forces to an agent
Creating a seeking agent requires two major components. The first is the ability to apply
force calculations to an agent while updating their forward direction, and the second is the
ability to clamp an agent's horizontal speed to its maxSpeed property.
Whenever we apply force to an agent, we will apply the maximum amount of force. In es-
sence, this causes agents to reach their maximum speed in the shortest time possible.
Without applying the maximum amount of force, small forces can end up having no effect
on the agent. This is important because steering forces aren't always comparable with each
other in terms of strength.
First, we'll implement an Agent_ApplyForce function to handle applying steering
forces to the physics system and update the agent's forward direction if there is a change in
the direction of the agent's velocity:
AgentUtilities.lua :
function AgentUtilities_ApplyPhysicsSteeringForce (
agent, steeringForce, deltaTimeInSeconds)
-- Ignore very weak steering forces.
if (Vector.LengthSquared(steeringForce) < 0.1) then
return;
end
-- Agents with 0 mass are immovable.
if (agent:GetMass() <= 0) then
return;
end
-- Zero out any steering in the y direction
steeringForce.y = 0;
-- Maximize the steering force, essentially forces the
agent
-- to max acceleration.
steeringForce =
Vector.Normalize(steeringForce) *
Search WWH ::




Custom Search