UnrealScript Game Programming Cookbook

(Chris Devlin) #1

AI and Navigation


142

NavigationHandle.SetFinalDestination
(NavigationHandle.PathCache_GetGoalPoint());

// The random point is any area within the NavMesh
FinalDest = NavigationHandle.
FinalDestination.Position;

// Draw the line to our pawn
DrawDebugLine(Pawn.Location, FinalDest,255,0,0,true);
/** Draw a red sphere to illustrate the next location
the bot
will stop at */
DrawDebugSphere(FinalDest,16,20,255,0,0,true);

The debug information is now drawn on screen so that we can see where our bot will
go. This visualization makes it far easier to understand if our bot is handling our code
correctly or not, especially the pathfinding.


  1. The following code represents what goes on behind the scenes, or within our bot's
    mind as it is looking for a new path. All of the pathfinding code is as follows:
    // While our bot hasn't reached the random point yet...
    while(!pawn.ReachedPoint(FinalDest, none))
    {
    /* If the bot realizes it can't reach this point
    directly...
    /


if(!NavigationHandle.PointReachable(FinalDest))
{
// Get out of here and pick another point
break;
}
// Otherwise...
else
{
// Move to the random point
MoveTo(FinalDest);
}
// Rest for (X) seconds before picking a new point
Sleep(0.5);
}
// Start from the beginning again
goto 'Begin';
}
}
Free download pdf