DEV Community

Isabel Puustelli
Isabel Puustelli

Posted on • Updated on

Complete game development blog #2: Pathfinding and distance calculation finished

Sometimes it's good to be humbled and reminded that you need to take a brake and really look at what you're doing from the outside in.

So I had finished my amazing idea of not having to do the calculations for the movement distances for my characters, since I was using the A* Pathfinder and thought I could just use the distance it calculated. And it worked, but the numbers seemed off. Traveling sideways doubled the distance compared to traveling straight up. I was racking my brain on this problem for the longest time until the obvious hit me.

My game is isometric. The pathfinder is not.

Image description
This image shows how the pathfinder calculated what tiles were inside a certain distance. It looks all well and good at first glance until you realize travelling vertically you can go up 3 tiles, but horizontally only a single tile! The pathfinder doesn't know or care what perspective the plane is under it, it only knows it exists in 2d space and that it needs to go from point A to point B through a grid of dots, while avoiding any obstacles.

Image description
This is what I didn't realize I wanted. A circle existing on the isometric plane.

Luckily it wasn't a difficult fix. The pathfinder provides a list of points it goes through, so it was as simple as converting those points into tile coordinates and applying a little bit of everyone's favorite theorem from high school.
Image description After adding all the parabolas together you get the correct distance.

PS: There probably could have been a way I could have set the grid of dots the pathfinder goes through to be isometric, but that's for someone else to figure out, this works for me.

Top comments (0)