Game Development Reference
In-Depth Information
Updating team influences
When setting influences based on the agent's position, we need to modify these positions to
correctly influence the cell the agent is occupying. As an agent's position is its midpoint,
we can clamp that position to the closest point on the navigation mesh in order to affect a
valid influence cell.
As the influence map is composed of three-dimensional cells, there are many more empty
cells compared to cells that intersect with the navigation mesh. Empty cells don't contribute
toward spreading actual influence, so it is important that setting an influence value affect a
cell that is overlapping with the navmesh.
Tip
Accidentally setting the influence of an empty cell is a common error when influences
might disappear momentarily and reappear as the agent moves around the sandbox. Always
clamp positions to the navigation mesh before using them for influence locations.
To update each team layer, we'll influence grid cells based on the closest position on the
navmesh our agents are standing on. team1 will influence the layer negatively, while
team2 will influence the layer positively.
SoldierTactics.lua :
local function UpdateTeamAreas(sandbox, layer,
deltaTimeInMillis)
-- Updates influences for both team1 and team2.
-- Remove all current influences, otherwise influences
-- compound.
Sandbox.ClearInfluenceMap(sandbox, layer);
local agents = Sandbox.GetAgents(sandbox);
for index = 1, #agents do
local agent = agents[index];
if (agent:GetHealth() > 0) then
-- Clamp each position to the navmesh.
local position = Sandbox.FindClosestPoint(
Search WWH ::




Custom Search