Game Development Reference
In-Depth Information
al ForceToTargetSpeed function is also added to pathing agents in order to make
sure that they don't fall below a minimum speed.
Creating pathing agents in the sandbox is identical to creating other agents, except that
this time, we'll create 20 different agents with varying speeds—all following the same
path. Once you run the sandbox, notice how agents will collide with each other and be un-
able to pass other agents. All we're missing is collision avoidance for a nice-looking path
following:
Sandbox.lua :
-- Default path to assign to path following agents.
local path = {
Vector.new(0, 0, 0),
Vector.new(30, 0, 0),
Vector.new(30, 0, 50),
Vector.new(-30, 0, 0),
Vector.new(-30, 0, 20)};
function Sandbox_Initialize(sandbox)
...
for i=1, 20 do
local agent = Sandbox.CreateAgent(
sandbox, "PathingAgent.lua");
-- Assign the same path to every agent.
agent:SetPath(path, true);
-- Randomly vary speeds to allow agents to pass one
-- another.
local randomSpeed = math.random(
agent:GetMaxSpeed() * 0.85,
agent:GetMaxSpeed() * 1.15);
agent:SetMaxSpeed(randomSpeed);
end
end
Search WWH ::




Custom Search