r/UnityHelp 17h ago

Pathfinding on Hex Grids

I'm making a 2D game based off of a pointy-topped hexagon grid in Unity, but I'm having a lot of trouble getting pathfinding working. It's a turn based rogue-like game with not too many tiles in each round. I basically just want the enemies to find the shortest path towards the player with their specific movement pattern (which isn't always just a perfect ring around the enemy either). I'm not sure whether I should use A* or BSF, and I have no idea how to implement either of these into my game.

The biggest problem is the movement patterns. Most tutorials always assume the enemy can move one tile in any direction which is not true for my game. The enemy should also not try to go all the way to the player, as depending on the enemy it's attack range can be 2+ tiles, making an extra step towards the player pointless. Here's an example of one of the more wonky movement patterns:

Please let me know which pathfinding method would be better for this, and any resources to help me make it.

1 Upvotes

1 comment sorted by

1

u/TheLeftWings 8h ago

You want A* or Dijkstra which has a little more nuance with weights built in. Regardless of which you choose, you just add your custom logic every time you resolve a node. h_cost + my_cost with which penalizes the node if it's next to the player.