Is it possible to so skip a node in the A star algorithm?

Hello, I’m doing a railway system and I’m trying to calculate the fastest path given two points so that the train automatically travels through the shortest path. However, there’s a type of rail which bifurcates, everyone knows that this rail lets the train change rails but only if the train is going in one direction not in another. That’s why I need to know if there’s a way to skip a node by checking the paren’t parent node. Where’s is all the a* algorithm?

Not out of the box.

However I guess you could do something clever…

Assume (hopefully this ASCII art will show correctly)

->-A-----D---*> / / A->--B--->-*

You can try using tags.
Tag the nodes as shown with different tags. (use e.g GraphUpdateScene)
In the image, a train could travel from A (bottom) to B, then switch rail to D and then continue towards the right.
An invalid move would be to move from A (top) to D then switch rail to B and then continue in any direction.

Then the tricky part. You would have to modify the PointNode.Open method (if using the latest beta), or the Node.Open method (if not).
Basically, you would check when looping through each connection.
If (this.tag == "B" && otherNode.tag == "D" && pathNode.parent.node.tag != "A") continue if (this.tag == "D" && otherNode.tag == "B) continue
The above would disable any move from B to D which did not have the parent A, and also disable all moves from D to B.
Due to the nature of A* and most graph searching algorithms, this might give you incorrect results in some rare cases. It might help to turn off the heuristic (A* Inspector -> Settings -> Heuristic).

You cannot use strings to check for tags in the real code, but you use numbers, the first tag is tag 0, the second one is tag 1, etc.

PS: I haven’t tested any code for this, but it feels like it could work.

That’s what I was hoping for, thanks a lot, I’ll try it out.

Works great!