Advertisement

Pathfinding noob, nodes instead of tiles

Started by March 17, 2010 05:39 AM
1 comment, last by Emergent 14 years, 8 months ago
Hi Im using pathfinding code i found on the net (A*). And i understand most of it. Its based on tiles so each tile connects automatically to each 8 tiles around it. In my new game i need to add nodes manually on the map and let my actors (ships on ocean moving between ports) pathfind these nodes to travel correctly. How would this work? My idea is to have all nodes check for suitable "neibours" beforehand and store this. The patherclass has functions like AdjacentCost, findPath etc. So you think i could modify the old tilebased class into something that works with arbitrary positioned nodes or does that work completely different? Thanks E
The A* algorithm isnt exclusive to tiles, it is actually a graph search algorithm, tile based a* just treats each tile as a node with 4 (or 8) connections to neighbour nodes. You could use any arbitrary number of nodes or layout of the nodes, you could use any mesh (essentially a 2d graph) where the mesh represents the sea (or seaways) and some nodes are ports. The ship could sail to the nearest node and run A* to find its way to port.
Advertisement
Also, the nodes in the graph that you search with A* don't have to correspond to points in your world; they can also correspond to regions. Then the edges of your graph just encode which regions are adjacent. This is the basic idea behind the popular navmesh concept.

This topic is closed to new replies.

Advertisement