UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 5

141

Again, if our bot realized that it can't directly access the point on the map, it will draw
a new one and move towards it. At the end of the function we tell the bot to rest for
half a second, and then start from the beginning again.


/*=======================================================



  • Patrols a map's NavMeshes using direct movetoward if
    player is reachable and pathfinding if not.
    =======================================================*/


auto state PatrolNavMesh
{
// If we see a player or pawn, ignore it
ignores SeePlayer;


function bool FindNavMeshPath()
{
// Clear cache and constraints
NavigationHandle.PathConstraintList = none;
NavigationHandle.PathGoalList = none;
NavigationHandle.bDebugConstraintsAndGoalEvals =
true;


/* this makes sure the bot wont wander into an area
where it will get stuck
/
class'NavMeshPath_EnforceTwoWayEdges'.static.
EnforceTwoWayEdges(NavigationHandle);


/* Tells the bot to set a random goal.
There are 2 optional
variables you can pass, a float or int representing
the range
to search, and an int representing how many polys
away he can
move to
/
class'NavMeshGoal_Random'.static.FindRandom
(NavigationHandle);
// set his goal.


// Find path
return NavigationHandle.FindPath();
}
Begin:
if(FindNavMeshPath())
{

Free download pdf