- Home /
Best approach to generating a grid for basic A* pathfinding
Quick Overview :
I'm going to be generating a multidimensional array (or list depending on what works best) of world positions that will make up my grid. My plan is to use the A* pathfinding algorithm to plot my characters movement through this grid.
The Question:
My first thought is as I'm going to be using A* I will probably need to create a "Node" class wrapper for my grids world positions to store various data such as the h cost, and g cost etc. Do I necessarily need to wrap my world positions in a class, what is the best approach to my grid generation in this case? Also what would you recommend storing the grid as, multidimensional array, or just straight list?
Answer by Kryptos · Jul 28, 2012 at 07:37 PM
A class
would be better than a struct
. Because classes are passed as reference whereas structs are just copies.
So I would suggest something like:
public class GridNode
{
public Vector3 v3Position;
public float fHCost;
public float fGCost;
}
As for the data structure, since A* means moving a lot nodes from/to lists, then use lists of lists.
Take a look at this alternative to straight A*: http://aigamedev.com/open/tutorials/theta-star-any-angle-paths/