Game Development Reference
In-Depth Information
userData.enemy:GetPosition()) < 16.0 do
endPoint = Sandbox.RandomPoint(
sandbox, "default");
end
path = Sandbox.FindPath(
sandbox,
"default",
userData.agent:GetPosition(),
endPoint);
end
Soldier_SetPath(userData.agent, path, false);
userData.agent:SetTarget(endPoint);
userData.movePosition = endPoint;
else
-- Randomly move anywhere if the Agent has no
current
-- enemy.
SoldierActions_RandomMoveInitialize(userData);
end
userData.controller:QueueCommand(
userData.agent,
SoldierController.Commands.MOVE);
return Action.Status.RUNNING;
end
Once a valid target position and path is found, the flee action acts very similar to a move
action with one exception, which is health. As our flee action continues to move our agent
until it reaches the target position, we must check whether the agent is still alive; other-
wise, we have to terminate the action early:
SoldierActions.lua :
function SoldierActions_FleeUpdate(deltaTimeInMillis,
userData)
-- Terminate the Action if the agent is dead.
Search WWH ::




Custom Search