Game Development Reference
In-Depth Information
Enemy selection
Converting the logic from the SoldierEvaluators_HasEnemy function only re-
quires modifications that return both a confidence value and the final result. Since only one
source will determine enemy selection, we will return a confidence of 1 , as well as the se-
lected enemy.
SoldierKnowledge.lua :
function SoldierKnowledge_ChooseBestEnemy(userData)
local sandbox = userData.agent:GetSandbox();
local position = Agent.GetPosition(userData.agent);
local agents =
Sandbox.GetAgents(userData.agent:GetSandbox());
local closestEnemy;
local distanceToEnemy;
for index=1, #agents do
local agent = agents[index];
-- Only check against living agents.
if (Agent.GetId(agent) ~=
Agent.GetId(userData.agent) and
Agent.GetHealth(agent) > 0) then
local distanceToAgent =
Vector.DistanceSquared(
position, agent:GetPosition());
if (closestEnemy == nil or
distanceToAgent < distanceToEnemy) then
local path = Sandbox.FindPath(
sandbox,
"default",
position,
agent:GetPosition());
Search WWH ::




Custom Search