3

A* and Dijkstra's pathfinding algorithms work by navigating a node map. In a tile-based 2D environment, these nodes could easily be inferred to be the literal x,y positions of the map.

For example, the agent is at (0,0), an obstacle is at (0,1), and the agent wants to go to (0,2).

However, in a 2D environment where locations are represented using floating point variables float x, float y, agents and obstacles can exist between the traditional style nodes (0,0) and (0,1).

How do you create a node map from such an environment?

Cory Klein
  • 133
  • 5

1 Answers1

3

The two most common answers are to use waypoints or navigations meshes (navmeshes).

In the former case, you pick various points on your map, precompute which are "neighbors" (have a clear path between them), and explicitly link them together.

In the latter case, you generate a triangle mesh covering all walkable regions. Your nodes can be triangles with graph-edges being the shared triangle-edges. Or nodes could be midpoints of triangle-edges with the graph-edges being computed from the triangles.

Sean Middleditch
  • 41,807
  • 4
  • 89
  • 132