I’ve been working on implementing A* Pathfinding onto my hexgrid tile map. They are flat tops.
I have gone through and added a point to each hextile and then connected those tiles. However, I came across an issue. I have specifically mentioned in my code which are the neighbour tile co-ordinates:
var neighbour_cells = [Vector2i(1,0), Vector2i(1,-1), Vector2i(0,-1),
Vector2i(-1,0), Vector2i(-1,1), Vector2i(0,1)]
Seems like it should work, but I will notice that sometimes it will connect tiles from a ‘further’ distance than it should. I’ve then added in the co-ordinates of each tile to see what was going on.
As you can see above, with the tile at 2,1 it will not connect to the tile at 3,-1 because that is 1,-2 and not included in the neighbour cells to check for. However, the 3,1 tile will include the 4,0 because according to the neighbour cells, it is a neighbour.
Looking at the tile 4,3 it does correctly need to connect to the tile at 5,2 (so the neighbour cell of 1,-1 is correct to check for) and the problem from above doesn’t exist here as it will not connect to 5,1
What do I need to do to ensure that a proper neighbour at 1,-1 is included but when it is essentially ‘two’ tiles away, it isn’t included?