Its really not that hard when you get down to the basics of it.
The main idea is that for each move you do a check in the 8 directions surrounding the zombie.
For instance, X is each spot you check, Z is the zombie:
X X X
X Z X
X X X
If X has something blocking it, you add points to it. If it is diagonal you add points. Then you add points based on its distance to the desired position. You then move the zombie
to whichever spot has the least points. for instance, if B represents a blocked square and O is desired point
X X X X X X
6 5 4 X X X
B Z 3 X X O
B 5 6 X X X
The zombie would then pick the square labeled 3, because it has the least amount of points.
In a more complex algorithm you would keep doing this and make sure the path is able to reach the target.
But for simple zombies and terrain that isn't too complex, this works fine. |