Page 1 of 1

Implementation details on the train pathfinding (same path)

Posted: Fri May 04, 2018 4:13 pm
by harmony
Hey

was wondering if anyone has some info on how all the wagons of a train are kept on the same path.
Trying to implement my own train project (not planning on selling anyhting) and it's something I'm stuck at, the only thing I can currently do is make them pick a random turn at intersections

Image
works fine when there's no intersection obviously

Image

Re: Implementation details on the train pathfinding (same path)

Posted: Fri May 04, 2018 11:24 pm
by betrok
I do not know how exactly the pathfinding works in factorio, but basically you have to build the weighted graph from your railroad.
The vertexes will represent intersections and possible other notable points such as stops. Weight of the edges can contain length of the section itself and stuff like a penalty for red signals.
harmony wrote:was wondering if anyone has some info on how all the wagons of a train are kept on the same path.
Well, all the wagons just follow the first one. Save the calculated path and use it for all of them.

Re: Implementation details on the train pathfinding (same path)

Posted: Fri May 04, 2018 11:57 pm
by Jap2.0