Game Development Reference
In-Depth Information
Agent.ForceToCombine(agent, 100, 180, { leader } );
-- Force to stay away from other agents that are closer
than
-- 2 meters and have a maximum forward degree
difference of
-- less than 180 degrees.
local forceToSeparate =
Agent.ForceToSeparate(agent, 2, 180, sandboxAgents
);
-- Force to stay away from getting too close to the
leader if
-- within 5 meters of the leader and having a maximum
forward
-- degree difference of less than 45 degrees.
local forceToAlign =
Agent.ForceToSeparate(agent, 5, 45, { leader } );
-- Summation of all separation and cohesion forces.
local totalForces =
forceToCombine + forceToSeparate * 1.15 +
forceToAlign;
-- Apply all steering forces.
AgentUtilities_ApplyPhysicsSteeringForce(
agent, totalForces, deltaTimeInSeconds);
AgentUtilities_ClampHorizontalSpeed(agent);
local targetRadius = agent:GetTargetRadius();
local position = agent:GetPosition();
local destination = leader:GetPosition();
-- Draw debug information for target and target radius.
Core.DrawCircle(
position, 1, Vector.new(1, 1, 0));
Core.DrawCircle(
destination, targetRadius, Vector.new(1, 0, 0));
Core.DrawLine(position, destination, Vector.new(0, 1,
Search WWH ::




Custom Search