Game Development Reference
In-Depth Information
How it works...
The key component here was adding PathNodes to our array. We created a variable to
store our array ( WayPoints) and then created an integer to iterate through each one
( _PathNode ). The first thing our pawn does upon spawning is add the PathNodes to
our array through waypints.AddItems(Current); in PostBeginPlay() .
Once they are in our array, we then iterate through them, one by one, until we've gone
through them all and determined that one of them is close enough, based on our
CloseEnough variable.
Making a pawn randomly patrol PathNodes
on a map
PathNodes are designed so that we can have complete control over how our bots progress
through a map. The problem with having a bot patrol PathNodes in a set path is that it doesn't
look very realistic, unless your bot is a guard patrolling a prison.
For that reason we want to create a bot that can patrol our PathNodes at random.
Getting ready
Open up your IDE and prepare to create a new class.
How to do it...
Our goal here is similar to what we did with our first recipe in the chapter. We want to
create a bot that wanders again, but this time we want it to take advantage of the PathNodes
we've laid throughout the map. This gives us far more control over the landscapes the bot
can traverse, as opposed to the previous manner, which gave the bot access to nearly every
location on the map.
1.
Start by creating a new class called RandomNodeBot . Have it extend from UDKBot .
class RandomNodeBot extends UDKBot;
From here on, our class is identical to the PatrolNodeBot class in every way
except for the PathFind() function.
2.
Rather than iterate through each node, we're going to set _
PathNode=Rand(WayPoints.length); , which selects a random
PathNode in our array.
/*=======================================================
* The meat-and-potatoes of the class.
 
Search Nedrilad ::




Custom Search