Pathfinding with MicroPather : costs calculations with sectors and portals
Posted
by
Adan
on Game Development
See other posts from Game Development
or by Adan
Published on 2011-02-24T10:22:55Z
Indexed on
2011/02/24
15:33 UTC
Read the original article
Hit count: 260
Hello,
I'm considering using micropather to help me with pathfinding. I'm not using a discrete map : I'm working in 2d with sectors and portales. However, I'm just wondering what is the best way to compute costs with this library in this context.
Just to be more clear about geometrical shapes I'm using : sectors are basically convex polygons, and portals are segments that lies on sector's edge.
Micropather exposes a pure virtual Graph class that you must inherate and overrides 3 functions. I understand how pathfinding works, so there's no problem in overriding those functions. Right now, my implementation give me results, i.e I'm able to find a path in my map, but I'm not sure I'm using an optimal solution.
For the AdjacentCost method : I just take the distance between sector's centers as the cost. I think a better solution should be to use the portal between the two sectors, compute its center, and then the cost should be : distance( sector A center, portal center ) + distance ( sector B center, portal center ). I'm pretty sure the approximation I'm using with just sector's center is enough for most cases, but maybe with thin and long sectors that are perpendicular, this approximation could mislead the A* algorithm.
For the LeastCostEstimate method : I just take the midpoint of the two sectors.
So, as you understand, I'm always working with sectors' centers, and it's working fine. And I'm pretty sure there's a better way to work.
Any suggestions or feedbacks? Thanks in advance!
© Game Development or respective owner