Game Development Reference
In-Depth Information
Enemy selection
With additional visibility information, we can update our enemy selection to take into ac-
count only agents that aren't teammates as well as ones that have been visible within the
last second. As teammates send out enemy sightings and essentially share their visibility
about the environment, the response time for our agents to pursue a newly spotted enemy is
rather quick.
Tip
Currently, our agents share immediate knowledge with each other. With only a small
amount of work, you can delay knowledge propagation or even preference agents in order
to select enemies they've seen firsthand.
Creating a new function for choosing the best enemy will now only process known visible
agents that are stored on the blackboard.
SoldierKnowledge.lua :
function SoldierKnowledge_ChooseBestVisibleEnemy(userData)
local sandbox = userData.agent:GetSandbox();
local sandboxTime = Sandbox.GetTimeInMillis(sandbox);
local position = Agent.GetPosition(userData.agent);
local team = userData.agent:GetTeam();
local visibleEnemies = userData.blackboard:Get(
"visibleAgents") or {};
local closestEnemy;
local distanceToEnemy;
for key, value in pairs(visibleEnemies) do
if ((sandboxTime - value.lastSeen) <= 1000) then
local agent = value.agent;
if (agent:GetId() ~= userData.agent:GetId() and
Agent.GetHealth(agent) > 0 and
agent:GetTeam() ~= team) then
local distanceToAgent =
Vector.DistanceSquared(
Search WWH ::




Custom Search