- Home /
2D Tile Based Game problem with A * Pathfinding Project
My game is 2d Roguelike game, I create tile map in the runtime and used GridGraph for pathfinding. Everything is fine before updating the map.
There are some NPCs walk on the map, each NPC occupy one grid, NPC can not overlap on the map so the grid occupied by NPC is unwalkable. When NPC moves, I set the old grid to walkable and the new grid unwalkable. Something like below
//set the old grid to walkable
GraphUpdateObject guo = new GraphUpdateObject(b);
guo.modifyWalkability = true;
guo.setWalkability = false;
AstarPath.active.UpdateGraphs(guo);
seeker.StartPath (start, end, OnPathComplete);
in the OnPathComplete function I used similar code set new grid to unwalkable
I modified the UpdateArea function of GridGraph
public void UpdateArea(GraphUpdateObject o)
{
Bounds b = o.bounds;
//use b.center store position need update
int oldPosX = (int)b.center.x;
int oldPosY = (int)b.center.y;
TileNode oldNode = graphNodes[oldPosY * width + oldPosX];
o.WillUpdateNode(oldNode);
o.Apply(oldNode);
for(int x = oldPosX -1;x <= oldPosX + 1;x++)
for(int z = oldPosY - 1;z <= oldPosY + 1;z++)
{
CalculateConnections(graphNodes, x, z, oldNode);
}
}
It's not working and with strange behavior, I set the connections is four, however some seeker moved like one grid have eight connections and there is no connections between the two grids.
It's very frustrating to me. Is there some mistakes in my implementation and is the A* Pathfinding Project is too heavy weight for a 2D tile based game, so I should use a light weight pathfinding script? Any suggestion would help me out of this desperate situation, thank you.
Your answer
