Monday, February 18, 2008

2pTD - Development Part 2 (A* Pathing)

Continuing in the series describing how 2pTD was built (Part 1):
When I set out to create this multiplayer game I knew the unit pathing system would be the most integral part of the whole system. Unit pathing is an algorithm which determines the path the unit will take from a source location to a destination. There are some great resources online for learning all about graph search algorithms. I chose the A* search algorithm for its simplicity.

There are two cases in the 2pTD game where pathing occurs:
1. When a tower is placed onto the field all units are checked to make sure that a path exists from where units currently are to where they are going.
2. When a new unit enters the field.

In retrospect the implementation of the system isn't exactly the greatest. Specifically, towers should take up a 2x2 area of the field instead of the 1x1 they currently do. This would make the paths of the units more interesting and would also greatly increase the placement options because the field size would be doubled.



Here is the pathing sandbox which was built for the purpose of developing the pathing algorithm and also to develop the networking system.