Skip to main content

Posts

Showing posts from June, 2022

The basics of A Star Pathfinding

Someone wanted to know how the code works for basic A* path-finding. Rather than reply in Facebook, I've made a quick post for it here. 1. create an array of nodes to represent your level.  It can be nodes with connections, or it can be a list of co-ordinates where connections are assumed to be NESW where a node exists.   Example 1:   level = {"001":[["002", 5.0], ["003", 5.0]], "002":[["001", 5.0], ["003", 5.0]], "003":[["002", 5.0], ["001", 5.0]]}    This is a dictionary based "mesh" type array, for easy reading. You can see it has 3 nodes arranged in a triangle. Each node is connected to two others, and in this case, the distance between each is 5.0 units.    It's easy to see how this mesh could be expanded. You just need more points. Each point must include its two neighbors and the distance between them.   Example 2:   level = [[0,1,1,0], [0,0,1,1], [1,1,1,0], [1,0,0,0