Game Development Reference
How it works...
There are numerous ways to spawn bots on a level, including UnrealScript, making a pawn
placeable, or using Kismet. To make things easy for us, we've gone the Kismet route, which
allows us to quickly adjust the spawn location, pawn, and controller from within the editor.
We can spawn our bot from any PathNode or PlayerStart node on a map by using it as
an object within Kismet. Moreover, the ActorFactory within Kismet allows us to select the
controller and pawn, which will be spawned at that location.
While there are a number of ways to manipulate how our bots spawn, such as having multiple
bots at once, creating a timer to have them spawn at a set rate, or only allowing a certain
number of pawns on the map at once, we've decided to keep it simple and only have one
bot spawn immediately after the map is loaded. The Level Loaded node makes this possible.
Essentially I've just used Kismet in this chapter, so that we can quickly iterate on what we've
done and make changes to the pawn within the editor.
If we did this in code, we'd have to close the editor, go to the IDE, and change the code so that
it spawns the appropriate bot, along with the correct controller (AI) that we want to use. With
Kismet we can simply use the ActorFactory to see all of the bots and controllers are at our
disposal, then press Enter to have them spawn.
Allowing a pawn to wander randomly around
With our PathNodes laid throughout our map and our bot now having the ability to spawn on
the map, we're ready to start adding functionality to the bot so that it has artificial intelligence.
Load up your IDE and prepare to create a new class.
How to do it...
This recipe will be the starting point for our topic on AI. We'll start by simply creating a bot that
randomly wanders around a map before moving onto more advanced things, such as creating
a bot which takes advantage of our pathfinding system.
We're going to start by creating a new class for our bot, called simply, WanderBot .
We don't need all of the complicated functionality behind the UDK and UT bot,
so we'll be extending from GameAIController, and only add what we need.