# Path Finding

This topic is 4412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm making a Turn Based Estrategy and I need some help with path finding. The moving action will be like Final Fantasy Tactics and Fire Emblem, will be shown to the player some squares in the map, then, the player click on a square and the Sprite must get the shortest way from the spot it was to the spot that the player clicked. I would like some help too to make a code that generates those squares, like, if the movement of the sprite is about 5 squares, I need to make a code that circundate the sprite with those squares, like, 5 for the left of the sprite, 5 for the right, 5 above and 5 below, and the diagonals must be placed with move-squares too. Thanks

##### Share on other sites
Use Dijkstra's pathfinding algorithm, centered on the current position of the unit, to determine the set of tiles that it can reach in one move as well as the path (and the path length) to follow to get to each of these tiles. You can then display accessible tiles, or have the unit follow a path to a clicked area.

##### Share on other sites
An algorithm you might want to look at is the A* (a-star) algorithm.

Wiki on the A* algorithm
A* tutorial

##### Share on other sites
I used someone else's A* pathfinding code and it broke my game. :(

I finally decided to write my own which is much better because I now know exactly how to manipulate the code for paths not found, characters blocking paths, when to crowd in and when to find another route etc. I struggled a bit to start with, but writing it all out on graph paper first made it much easier to understand and was a good exercise for me.

Good luck with it!

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013710
×