Game Development Reference
In-Depth Information
Creating a path following agent
Creating a path following agent is very similar to our seeking agent, which is SeekingA-
gent.lua . First, create a new Lua script for the PathingAgent.lua agent:
Create the Lua file as follows:
src/my_sandbox/script/PathingAgent.lua
This time, we will utilize a DebugUtilities function in order to draw out a path for us.
DebugUtilities is a Lua script in src/demo_framework/script/De-
bugUtilities.lua . When we initialize our pathing agent, we'll assign it the path to be
traveled. Paths are considered looping by default, so our agent will keep traveling in a large
circle:
PathingAgent.lua :
require "AgentUtilities";
require "DebugUtilities";
function Agent_Initialize(agent)
AgentUtilities_CreateAgentRepresentation(
agent, agent:GetHeight(), agent:GetRadius());
-- Randomly assign a position to the agent.
agent:SetPosition(Vector.new(
math.random(-50, 50),
0,
math.random(-50, 50)));
end
function Agent_Update(agent, deltaTimeInMillis)
local deltaTimeInSeconds = deltaTimeInMillis / 1000;
-- Force to continue moving along the path, can cause the
-- agent to veer away from the path.
local followForce = agent:ForceToFollowPath(1.25);
Search WWH ::




Custom Search