Pathfinding for tile-based environments with obstacles
This recipe will show you how to solve the pathfinding problem in your game by using the A* algorithm. You can use this whenever you need to move from one point to another in an unknown environment. It uses heuristics to improve the search speed and efficiency. The good thing is that you can use it with any shape of tile. The most common use of the A* search algorithm can be found in strategic games, many action games, and tower defense games. Its use can be extended beyond pathfinding problems to adapt AI decisions to the environment or to make a dynamic liquid-like environment.
Getting ready
The A* searching algorithm makes extensive use of the priority queue data structure and it needs to access map cells quite frequently. For this purpose, you'll be using a slightly modified version of the priority queue and map2D structure.
You can use the following code to define the priority queue object:
-- useful shortcuts local ti = table.insert...