A* selective path finding using allowed waypoints

I’m working on simple traffic AI. I’m using point graph to create road lanes and I’d like for car to use not the shortest path, but only use waypoints that are allowed. Currently car just picks shortest path which can result in car going upstream or cut turns (pic 1).

I was wondering if it’s possible to find a path, that takes into account where you can move from given waypoint ( example on pic 2).
Is there a way to control path finding process?
Is there a better approach for case like this?

P.S.
I posted similar (more high level) question on unity forum, be assured that I’m not spamming forums with questions, I’m just looking for an advice a bit more specific to A*.

Hi

That’s technically possible, but I would suggest looking in to a pathfinding system specifically created for handling traffic systems. The reason is that for vehicles you cannot just use the a node and it’s position, you need to know the approximate direction of the vehicle on that node (which essentially means each node is duplicated say 8 times if 8 directions are used) and the rules for which connections to use can be tricky.
It is possible to do this (see http://arongranberg.com/astar/docs/writing-graph-generators.php), but it might be better with a special purpose system.

1 Like

Thanks for quick answer and for the link.
It’s more like a hobby-learning project, so I don’t mind getting my hands dirty a little bit.

Assuming I’m generating graph, how do I set rules for which connection to use? If I create connection between, say point “green” and point “brown” from my picture, does it automatically set connection between point “brown” and “green”?
Can I create separate connection between point “brown” and “green” and set connection cost to very high value so that pathfinding algorithm would avoid it?

Edit
Answering my own questions:
Adding connections works only one way ( http://arongranberg.com/astar/docs/class_pathfinding_1_1_point_node.php#a7737fe4ce16263109be7c0040bd001da )
So it basically answers the rest.
Once again, thanks for help.

1 Like