# Pathfinding with direction considerations

Consider the following road network. The car (orange) needs to get to the red circle. It drives on the right hand side of the road and is initially facing down.

The shortest path is the blue one. But if it follows this path, it reaches the red circle on the wrong side of the road. To actually get to the red circle, it needs to take the green path - much longer. The pink dots represent the nodes - the road network is made up of modular road pieces. Each node also stores all the possible directions a vehicle could take from that piece.

How can I make a pathfinding algorithm that takes this into consideration?

• Do you know on which side of the road the goal is ? Commented Jun 10, 2019 at 2:32
• Yes. I know the position and orientation (and thus the side of road) the goal is. The goal isn't necessarily at a pink node - it could be between them but it will always be on a straight section. Commented Jun 10, 2019 at 2:34
• If being on the left side of the road is different than being on the right side of the road, then those two states need to be two different nodes. Once you've created nodes for the distinct states you care about, and set up their adjacency graph correctly, a completely vanilla pathfinding algorithm will find the shortest path that puts you on the correct side of the road. Commented Jun 10, 2019 at 2:35
• What about reverse pathfinding ? From the goal to the car, this way you can vanish out cells that are in opposite side of the road ? Commented Jun 10, 2019 at 2:35
• Then I have the same problem but at the other end. If I go from the red dot along the blue line, I will end up on the wrong side. I would have to go right at the T intersection and loop back around. Commented Jun 10, 2019 at 2:38