|Topic was automatically imported from the old Question2Answer platform.
|Published before Godot 3 was released.
Hi guys. I’m looking to implement pathfinding in a 2D strategy game using a hex tilemap.
I’ve been following the example from GitHub - FEDE0D/godot-pathfinding2d-demo: A demo project demonstrating pathfinding using a tilemap on the Godot Engine and it works fine for square tiles but I’m finding hexes more difficult to work with. I’m basically drawing the nav poly instance around each hex tile that I want traversable, but there are only 2 points generated by get_simple_path so I’m guessing the nav poly instances don’t fit together properly.
Is there another way to do pathfinding with hex tilemaps, is there something I’m missing, maybe should I use the A star class instead?
Can you show a picture of what you get compared to what you want?
Do you imlply that the path you want should actually go through one of the 6 directions of a hex instead of crossing them? Because if that’s the case, you may want a different pathfinder like the AStar one so that you can choose which waypoints to traverse (in any case that will require some scripting to get that constraint). Making your own pathfinder is also an option.
Zylann | 2017-05-23 12:43
So I followed the example in the pathfinding2d demo linked in the question pretty closely, the only difference being I used hex tiles as opposed to squares. And the result I try to show in the image above with black arrows, is that the sprite literally only goes to the adjacent (horizontal) hex, one at a time. And there are only two points in the path, even when I want the sprite to go several hexes away (e.g. the red points I marked in the image).
And yes, I do want the path to go through one of the 6 directions of a hex. To be honest, I don’t really know how navigation2d/navpolyinstance/get_simple_path works and wasn’t sure if it would work with hexes in the same way it would work with squares in a tilemap. I think you’re right it would probably be easier to script with AStar, I might give that a shot.
hnuqweasd | 2017-05-23 14:22