Is there a way to prefer existing paths in a recast multi path?


I’m trying to generate a road system with a multi path. I would like to prefer existing paths if possible – for example, in the screenshot, the yellow circle highlights an area which has two nearby paths, but I would like the second path to adhere to the first as long as possible.

I’ve solved this in other A star implementations by just heavily weighting nodes with an existing path on them.

Is there a way to enable that with a recast graph / multi path? Or another combination that might work well?




You could find the paths one at a time, and every time you have calculated a new path, you can add a penalty to all other nodes in the world.

Or alternatively (but more performant):

  1. Give your seeker a list of tag penalties, with tag=0 having a very large penalty, and tag=1 having a penalty of zero.
  2. Find a path to one of the targets.
  3. Set the tag for all nodes in the path to tag=1.
  4. Repeat from 1.

How large the penalty is will determine how well it will try to stick to previous paths.



I tried the tag approach and it works perfectly, many thanks!