Game Development Reference
In-Depth Information
-- Force to move to the closest point on the path.
local stayForce = agent:ForceToStayOnPath(1);
-- Slight deviation force to alleviate bumping other
pathing
-- agents.
local wanderForce =
agent:ForceToWander(deltaTimeInMillis);
-- Sum steering forces using scalars.
local totalForces =
Vector.Normalize(followForce) +
Vector.Normalize(stayForce) * 0.25 +
Vector.Normalize(wanderForce) * 0.25;
local targetSpeed = 3;
-- Accelerate pathing agents to a minimum speed.
if (agent:GetSpeed() < targetSpeed) then
local speedForce =
agent:ForceToTargetSpeed(targetSpeed);
totalForces = totalForces +
Vector.Normalize(speedForce);
end
-- Apply the summation of all forces.
AgentUtilities_ApplyPhysicsSteeringForce(
agent, totalForces, deltaTimeInSeconds);
AgentUtilities_ClampHorizontalSpeed(agent);
-- Draw the agent's path as a looping path.
DebugUtilities_DrawPath(agent:GetPath(), true);
end
The Agent_Update function has a few new additions, which show you how to add two
steering forces together. Both ForceToFollowPath and ForceToStayOnPath are
added together with a lower weight associated with the StayOnPath force. An addition-
Search WWH ::




Custom Search