Reputation: 1223
I have an XNA zombie survival game, where the player has to hold out in a building and zombies come at them by waves. Zombies initially target barricades to get to the player, and then target the player once they break down the barricade.
Here is an image of the game so far. Walls (indestructible) are in black/grey, barricades are in brown:
UPDATE: I have made a lot of progress so far in my understanding of pathfinding, but still no dice. The above picture shows my current grid/node system.
As you can see, outside the "arena" there are very few waypoints. The zombies need to get to their nearest waypoint on a road, so they can then head towards the barrier (the top road still needs a barrier, I know).
Once they break down the barriers they need to use pathfinding to find and follow the player around walls and obstacles, so there are a lot more waypoints.
I am currently storing each of the grid points in a Microsoft.XNA.Framework.Point
array. I have tried so hard to implement this with this article which I have referenced so much, but my system and his are completely different and I can't find a way of making it work. For example, the article's system looks one grid unit in each direction to look for a node neighbour. Seeing as the waypoints outside the arenas don't have node neighbours right next to them, the system fails.
XNA is a dying framework and there is no usable articles/tutorials on pathfinding so I really need some help here.
Upvotes: 2
Views: 1142
Reputation: 11273
With an a* style pathfinding algorithm, a grid based game level is ideal, as an array of data provides the a* algorithm with what it needs to determine an optimal path.
When you move away from grid-based games, you need to get a little more clever. Your best option is to create a node based a* pathfinder. This implementation requires you to define "nodes" in your level, that serve as waypoints, in a path. Your algorithm utilizes the pre-defined nodes, in a modified a* implementation, to determine the optimal path.
You can even generate these waypoint nodes programatically based on your level. I wrote an implementation in unity described here .
Beyond this, you can look into Navigation Meshes. This technique involves calculating or pre-defining polygons in your level that allow movement. This is a bit more involved, but produces much better results.
Upvotes: 3