How do i make node based pathfinding; is it hard?

i didnt use pathfindingsevices for my old system, heres an explanation of how it worked:
NPC targets a random node (first move)
NPC looks in a folder inside that node, in that folder are object values saying wher it can move next
NPC Puts those nodes it can move to into a table
NPC Chooses a random one
NPC Moves to that random node, then it clears that table and the cycle repeats

2 issues with this system:

  1. NPC couldnt choose any node, then (using other nodes) pathfind to it
  2. NPC would randomly go to nodes that it should not be able to, nor has in its table data

What I would do is use the nodes you have in the folder to generate a graph in code that represents the nodes and their neighbors. You can pass the graph into an A* solver (you’d need to implement this yourself or find an implementation online) and get a path back. From there, you just have the NPC traverse the path.

Doing this would address both issues you had with your old system:

  1. Instead of choosing random nodes, the NPC is following an exact path so it knows which node it needs to walk to next.
  2. Assuming you’ve set up nodes and the object values in the folder correctly, it should be impossible for a path to be calculated that involves moving to nodes that are not neighbors with other nodes.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.