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?
Thanks!
Hi
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):
- Give your seeker a list of tag penalties, with tag=0 having a very large penalty, and tag=1 having a penalty of zero.
- Find a path to one of the targets.
- Set the tag for all nodes in the path to tag=1.
- Repeat from 1.
How large the penalty is will determine how well it will try to stick to previous paths.
See https://arongranberg.com/astar/docs/seeker.html#tagPenalties
I tried the tag approach and it works perfectly, many thanks!
1 Like