Game Development Reference
In-Depth Information
within 3.0 meters of the enemy, the pursuit ends and another action can be run. As pursuit
is a long running action, we also check for the health condition of our agent that can ter-
minate pursuits early:
SoldierActions.lua :
function SoldierActions_PursueUpdate(deltaTimeInMillis,
userData)
-- Terminate the Action if the agent dies.
if (Agent.GetHealth(userData.agent) <= 0) then
return Action.Status.TERMINATED;
end
-- Constantly repath to the enemy's new position.
local sandbox = userData.agent:GetSandbox();
local endPoint = userData.enemy:GetPosition();
local path = Sandbox.FindPath(
sandbox,
"default",
userData.agent:GetPosition(),
endPoint);
if (#path ~= 0) then
Soldier_SetPath(userData.agent, path, false);
userData.agent:SetTarget(endPoint);
userData.movePosition = endPoint;
offset = Vector.new(0, 0.1, 0);
path = userData.agent:GetPath();
DebugUtilities_DrawPath(
path, false, offset, DebugUtilities.Red);
Core.DrawCircle(
path[#path] + offset, 3, DebugUtilities.Red);
end
-- Terminate the pursuit Action when the Agent is within
-- shooting distance to the enemy.
if (Vector.Distance(userData.agent:GetPosition(),
userData.agent:GetTarget()) < 3) then
Search WWH ::




Custom Search