Saturday, January 30, 2021

RPG: Pathfinding

This month I decided to tackle pathfinding, and it came out really well. The world is a giant grid of tiles - some you can walk through, some you can't, and some you can only walk into from certain directions.

I'm using the A* algorithm to find paths from a character's current position to its destination. The A* algorithm as implemented is smart enough to know which tiles can only be entered by limited directions.

In addition to the A* algorithm to pathfind the static tiles, there are also obstructions of dynamic characters that can be in the way. And those obstructions can be of 2 shapes - circular (tree for example) or rectangle (bed for example).

If the moving character encounters one of these dynamic obstructions, it traverses around the obstruction in the shortest route possible to stay on its A* path.


Enemies are far more deadly now; you can't just hide behind a tree and get them stuck. Also it's now trivial for me to have villagers pathfind across town to accomplish various activities throughout the day.


No comments:

Post a Comment