|
BOXHEAD'S NAVIGATION SYSTEM
AI PT 3: BOXHEAD'S Navigation SYSTEM. I have been asked a lot of times how the navigation and object avoidance is achieved in Boxhead
Before reading this, it is really important to read the AI PT 2: THE MAP SYSTEM article below, as this is the basis for the navigation system.
How do we do this? Well it is pretty simple, we flood-fill the map, if you are unfamiliar with this, then please read http://en.wikipedia.org/wiki/Flood_fill, this explains it really nicely. However, we want to make sure we fill the map one step at time from the Players position because we want the numbers to count away from the destination (the player), the Player is 0 and the cells away from the player are > 0. Let's look at how we do this: class NavCell extends Cell Let's take the original Map cell class and extend it to make a new Class, NavCell. Now we have the NavCell we can create some properties that I think we will need to perform a flood fill. These properties will give us the result in Fig 1.1
{ Now instead of creating new Cells we now create new NavCells for the map.
for ( var iy:int = 0; iy < MapHeight; iy++) Now let's fill the Map from the Players position:
// Create a list of NavCells to work with to start the fill
// Set The index to 0 - as 0 is the destination
// ??? Remember this, we will go over it later You can see here that the Player's cell is added to the NavCells and the call to FloodMap_Step is only called then there is a cell in the NavCell. Let's write this function and mark the map.
function FloodMap_Step( cells:Array, id:int):Array HINT: You could cache these different directions with in the class NavCell and create them when you create the map.
// has the cell already been processed?
// same for South/West/East
Now we said we would look at what the NavID is, well this ID allows us to check whether a cell has been processed or not, we don't want to check the same cell twice as the Flood fill will never end. Why not just clear the NavIndex? Well this makes it so you don't have to, you can just process the Navigation every time the player moves (or things change) and not have the overhead of the clear. Now the Navigation becomes really simple for the Zombie, move to the next lowest cell surrounding the Cell it is on. When there is a ZERO in the adjacent cell then attack or do something... Another Scenario:
Well this is a little more complex but the same thing applies except you add all the cells that the player's barricades are on.
// Add all the barricades to the NavCells Now continue with same as before and the NavMap will end up like FIG 2.1. Hope this helps to progress your game. Any questions let me know on the email below,
Sean Cooper
|
||||||||||||||||||||||||||||||||||||



