Game Development Reference
In-Depth Information
The flee action
To create a flee action that causes our agent to run away from its enemy, we need to first
find a valid path that is at least 4.0 meters away. Picking an arbitrary point on the navmesh
will work, but we must ensure that there is a valid path to that point from the agent's cur-
rent position:
SoldierActions.lua :
function SoldierActions_FleeCleanUp(userData)
-- No cleanup is required for fleeing.
end
function SoldierActions_FleeInitialize(userData)
local sandbox = userData.agent:GetSandbox();
if (userData.enemy) then
local endPoint = Sandbox.RandomPoint(sandbox,
"default");
local path = Sandbox.FindPath(
sandbox,
"default",
userData.agent:GetPosition(),
endPoint);
-- Find a valid position at least 16 units away from
the
-- current enemy.
-- Note: Since pathfinding is not affected by the
enemy,
-- it is entirely possible to generate paths that
move the
-- Agent into the enemy, instead of away from the
enemy.
while #path == 0 do
endPoint = Sandbox.RandomPoint(sandbox,
"default");
while Vector.DistanceSquared(endPoint,
Search WWH ::




Custom Search