Game Development Reference
In-Depth Information
Updating dangerous influences
Updating dangerous influences requires processing each of the stored events similar to how
agent positions were calculated previously. Always remember to clamp the event location
to the navigation mesh regardless of whether the event actually took place at a position that
was slightly higher than the influence map cell.
For instance, a bullet impact can take place in an empty influence map cell as the agent's
shot might go high and hit a wall. Clamping the location to the navigation mesh will allow
these impacts to influence dangerous areas; otherwise they would be discarded from contri-
bution:
SoldierTactics.lua :
local function UpdateDangerousAreas(
sandbox, layer, deltaTimeInMillis)
-- Updates dangerous areas from team2's perspective.
-- Remove all current influences, otherwise influences
-- compound.
Sandbox.ClearInfluenceMap(sandbox, layer);
-- Remove bullet impact events that are too old.
bulletImpacts = PruneEvents(bulletImpacts,
deltaTimeInMillis);
-- Add influences for all bullet impact positions.
for key, value in pairs(bulletImpacts) do
-- Clamp each event position to the navmesh.
local position = Sandbox.FindClosestPoint(
sandbox, "default", value.position);
Sandbox.SetInfluence(sandbox, layer, position, -1);
end
-- Remove bullet shot events that are too old.
bulletShots = PruneEvents(bulletShots,
deltaTimeInMillis);
Search WWH ::




Custom Search