Pathfinding during runtime questions

Hello all, thank you for reading and helping. I am considering purchasing A* and would like to know the following before purchase. Backstory, I am building a game similar to Sim City in which I will have cars as well as people moving around. I think A* might be a solution to my traffic issues since cars/people will be able to adjust paths as streets/paths are created by the player, but I want to make sure two things.

  1. If I create a street, and put a car on it, and give that car a destination, I am assuming I will need to put invisible walls along the street so the car stays on the street (similar to a maze) and does not directly go to the target destination off-road. Is there a simple way to make sure that cars will stay on the right side of the road, so I can have cars pass one another? I was thinking of putting a small invisible wall in the center of the road, but that would make it difficult/impossible to put in a intersection. Are there any known solutions to keep cars on one side of the road?

  2. Is there any alternative solution to the wall idea I have in question 1? For instance, if I use the wall scenario for walking paths for people, then they would only walk on the outside of a park (or the paths within the park). It would be nice to have the ability for some random % of people cut across the park (as humans do), but I do not think I would be able to do that with invisible walls. Any ideas?

Thanks, I appreciate your time and responses.

HI

I would not recommend walls or anything like that. This is definitely the job for a more domain specific pathfinding graph. You would create a graph that only goes along the roads and nothing else, connections would be one directional to prevent cars from going in the wrong direction, and intersections would have some complicated pattern of connections which matches the traffic rules. Unfortunately the A* Pathfinding Project does not have such a graph type built in, however it is possible to write your own graph type: http://arongranberg.com/astar/docs/writing-graph-generators.php.
I must warn you that it is not going to be trivial to create this graph because traffic rules are complicated.
(also if you do decide to do it, there is one feature in the package that you will need to disable to be able to handle one directional connections well, but we can discuss that later, it’s not complicated to disable it).