Game Development Reference
In-Depth Information
The pursue action
Pursue is the exact opposite of flee, as our agent will track down its enemy instead of run-
ning from it. For this, we first find a path to the enemy and then begin moving toward it.
Typically, our agents will default to this behavior if they have a known enemy and suffi-
cient health to engage the enemy:
SoldierActions.lua :
function SoldierActions_PursueCleanUp(userData)
-- No cleanup is required for pursuit.
end
function SoldierActions_PursueInitialize(userData)
local sandbox = userData.agent:GetSandbox();
local endPoint = userData.enemy:GetPosition();
local path = Sandbox.FindPath(
sandbox,
"default",
userData.agent:GetPosition(),
endPoint);
-- Path to the enemy if possible, otherwise idle and
-- constantly try to repath to the enemy.
if (#path ~= 0) then
Soldier_SetPath(userData.agent, path, false);
userData.agent:SetTarget(endPoint);
userData.movePosition = endPoint;
userData.controller:QueueCommand(
userData.agent,
SoldierController.Commands.MOVE);
end
return Action.Status.RUNNING;
end
As the enemy agent will typically be moving, we need to update our agent's path during the
update loop so that the agent can track down the enemy's new position. If our agent gets
Search WWH ::




Custom Search