What is the best way to detect that I have reached a waypoint and possible passed it?
I currently manage the waypoints in a way that works well when the train stops at one. The train constantly adjusts it’s deceleration to make it stop at the right spot relative tot he waypoint. Once the train stops, I check and see that there is a current waypoint and that it was the one that stopped the train. If there were to be two waypoints and somehow the later waypoint was the one that stopped the train, the earlier one would essentially have been skipped. There is no action that can happen unless the train stops.
Now I have waypoints that don’t stop the train. These are used to force the train through a section of track but no stopping is needed. I will make these work by storing the distance from the train to the waypoint in the waypoint and then detecting when this goes negative. The problem is that I can imagine running the game at such a high simulation rate that the train jumps way past a waypoint and then never sees it to even store the distance value that is now negative. I don’t want to be looking backwards for these things.
There is also a problem with using a non-stopping waypoint. If the train is not stopping then it will be making route decisions past the waypoint. That is actually a problem anytime the length of the train causes the front of it to go onto a new track segment while the train is still not stopped. I need to pick a route if there is a turnout which means looking ahead at the waypoint after the one we are using.
What the heck do I do if there are waypoints so close together that even the next waypoint after the current one doesn’t allow us to pick a route. Do I just go through all of the waypoints until I can figure out what route to take or do I assume that the player won’t normally place them that close together? Can I restrict that distance?
I’m writing about this because I was thinking about it a few minutes ago and these things came to mind. Hopefully, I’ll have a solution in the next few days or at least handle the obvious issues of non-stopping waypoints by then.