Update 1: updated the animation system to plot chords and move. The significance of chords is the geometry of train cars. Train cars have two bogies, one at the front and one at the rear. The distance between those bogies is constant in world space (i.e. 3D) because there's a rigid chassis connecting the two together, but in curve space (i.e. 1D) the distance between the two increases as a curve gets sharper.
So, there’s two problems: how am I going to move the train but keep the chord distance the same? And how am I going to detect when the train reaches the end of the track, since you know there’s going to be rogue operators.
To make collision detection easy, the side the train is going towards has a constant velocity and detects if the end of the track is reached (and maybe in the future, if there is a train to couple to).
If that side of the train hits an obstacle (like the end of the track or another train), it can tell all the bogies and cars behind it to slow down so everything doesn’t crumple into an incomprehensible pile.
This is a cheat.
Simulating the trains in this manner does not represent how real trains operate, and the reason has to do with chords.
Not quite guitar chords
The front (or rear) of the train moves at a constant speed, insofar as its speed is not affected by the issue outlined below.
Trains, like cars, have front wheels and they have back wheels. The distance between those wheels is constant, because they’re connected by a steel frame that won’t shrink even if you ask real nicely.
Here’s the funny thing, when the train is moving between straight track and curved track, or between curved track and straight track, the front wheels are not spinning at the same speed as the back wheels. When entering a curve in real life, the front wheels will speed up and the rear wheels will slow down, and when exiting a curve, the front wheels will slow down and the rear wheels will speed up. This is because the distance along the curve is increasing and decreasing, even though the straight line distance is not (that straight line distance is a chord).
The reason that’s an issue is because the front of the train (or the back, if it’s reversing), goes at a constant speed in this animation system, because as much as I like realism, it’s a bit beyond what Firestone needs and just takes up valuable computation time.
You might ask why I don’t drive the train from the center, to be able to limit the speed changes caused by the chords, and the answer is collision detection, as mentioned above.
So why even bother with chords? I’ve made several CFrame train systems in the past that didn’t require this behavior. They were all for model trains, not full-size ridable trains, and did not have turning bogies. At a small scale, these oversights are exusable. But Firestone has used physics since its inception, and to have static bogies would look out of place. If I implemented turning bogies without the chord system (and relied solely on curve space), the wheels beneath the train would scrunch up underneath the train when it goes around a corner. For loose corners it might not be that noticeable, but the meeting complex corner is very sharp! It would look completely wrong if it were to happen. So I spent the whole day implementing this one feature because you guys deserve it.