Game Development Reference
In-Depth Information
Flee position selection
Extracting the flee position calculation from SoldierActions_FleeInitialize
takes a bit more work but is just as easy. As the previous flee position calculations were us-
ing additional information on the userData structure, we can convert the use of userData
values into values provided by the blackboard directly.
SoldierKnowledge.lua :
function SoldierKnowledge_ChooseBestFleePosition(userData)
local sandbox = userData.agent:GetSandbox();
local enemy = userData.blackboard:Get("enemy");
local bestPosition;
if (enemy) then
local position;
local bestDistance = 0;
local enemyPosition = enemy:GetPosition();
-- Try 32 points, and pick the furthest point away
from
-- the current enemy.
for index=1, 32 do
position = Sandbox.RandomPoint(sandbox,
"default");
local distanceToAgent =
Vector.DistanceSquared(position,
enemyPosition);
if (bestDistance < distanceToAgent) then
bestDistance = distanceToAgent;
bestPosition = position;
end
end
else
-- Any position will work if the agent doesn't have
Search WWH ::




Custom Search