Game Development Reference
In-Depth Information
Initializing the navmesh
The creation of the navmesh occurs only once and uses default values, as our agents also
use the sandbox's default values. When we spawn a new agent, we'll randomly place them
somewhere in the navmesh:
Sandbox.lua :
local _agents = {};
function Sandbox_Initialize(sandbox)
-- Create the sandbox level, handles creating geometry,
-- skybox, and lighting.
SandboxUtilities_CreateLevel(sandbox);
-- Override the default navigation mesh config
generation.
local navMeshConfig = {
MinimumRegionArea = 100,
WalkableRadius = 0.4,
WalkableClimbHeight = 0.2,
WalkableSlopeAngle = 45 };
Sandbox.CreateNavigationMesh(
sandbox, "default", navMeshConfig);
Sandbox.SetDebugNavigationMesh(sandbox, "default", true);
-- Create agents and randomly place them on the navmesh.
for i=1, 5 do
local agent = Sandbox.CreateAgent(
sandbox, "IndirectSoldierAgent.lua");
table.insert(_agents, agent);
agent:SetPosition(
Sandbox.RandomPoint(sandbox, "default"));
-- Use the Agent's closest point to the navmesh as
Search WWH ::




Custom Search