Saturday, January 31, 2015

Exploring A* in Unity!

So I was introduced to Shattered Pixel Dungeon last week, and interestingly, it's not as addictive as I thought it'd be. It's great to spend a few turns playing it before bed or whilst on the can.

Pathfinding isn't something new, and I've actually coded A* in C++ years ago... not sure if it's still on the blog somewhere. But I was like.. yeah, pathfinding rules! Let's code it up in Unity! Plus I've not had a chance to play with the new UI in 4.6, so this was good fun.

The distance parameter, H, changes the results quite dramatically. Originally, I used the Manhattan Distance (I was following this tutorial) and while you get a solution, it was quite meh. Changing it to simply the distance between the selected node and target provided a much improved result.

No comments: