Automatic path finding


I currently working on a railroad switch Gui and I want make a system who trace a path between two points (see picture below). How can I do a system who find the path between this two points ? I tried to use pathfinding service or things like that but it doesn’t work because it don’t use tracks.

Can you help me please ?

Without path found:

With path found:

I think you would need to define each switch as a ‘node’, then give each route from the switch a ‘weight’ and use something like Djikstra to calculate the best path.


If you are interested in what @BadDad2004 recommended. Here is a plugin and article for easy use of nodes and Pathfinding. For more complex use of Nodes with Pathfinding, ← this is what u may want if switching and rerouting tracks occur in your game.

Note: I have not Tested A*(Improved Djikstra) with 2D, but it’s possible; maybe not with the Plugin(above) though.