DEV Community

Isabel Puustelli
Isabel Puustelli

Posted on • Updated on

Complete game development blog #1.5: Pathfinding

I was about to start implementing the movement system I talked about in my last post, but once I remembered I needed some kind of pathfinding for tiles that are around corners, I realized I could get two birds with one stone.

First things first I want to shout out someone who is a lifesaver to all 2D unity developers. Aaron Granberg made an amazing opensource project called the "A* Pathfinding Project". It's such an amazing, simple, easy to understand pathfinding solution for unity games, especially for 2D since navmesh isn't an option. I toyed around with the idea of doing A* pathfinding on my own, but making a game on you're own is enough of an undertaking in and of itself so any outside help is always nice.

So back to the shortcut idea. Since i had to implement pathfinding for obstructive objects and walls, i might as well use it for all movement. Since i was going to use the circle method, I could use the pathfinding to find out whether a tile is inside a certain sized circle or not. The simplest way to find that out, is to know if the tile is closer to the player than the circle's radius. So i simply compare the path length to the players movement range. You could say this is a bit of a twisty way to arrive at a very simple solution, but I had to make sure it's balanced in the way I wanted it, and I'm happy to say, it is. And this is what it currently looks like.

An image of a character with a line forming from it to the cursor signifying the calculated path. A number next to the cursor shows the length of the path.

Top comments (0)