I’ve done a lot of looking around on different ways to get trains to follow turns, and I found several ways that would be great for a standard train system.
However, I have a trolley-like platform that’s able to move back and forth at the control of the player. The player is able to start and stop the train at any time he wishes, and the train is able to move in both directions.
I have the train itself set up so that it can move back and forth, with the player inside, at the control of the player. However, I’ve tried many ways of getting the train to turn or switch tracks, depending on how the controls are set.
I have a script for causing the train to go up a hill, but it seems more complicated than it should be.
I looked at the Spline script on the wiki, and it’s great for causing the train to turn the corner at a nice, smooth rotation. However, it seems to be only good for one direction, and only once. Theoretically, in order to have the train be able to stop and go the other way in mid-turn, there would have to be two Spline curves on the same track, since the train follows the points in alphabetical order. Not to mention the trouble of having the train come to a split in the track and having to be able to choose which line to follow based on player input.
The track system is supposed to be able to have possibly dozens of hills, turns, and splits all throughout, so I need a solution that’ll allow me to effectively prefab something into the track segments.
With this in mind, I tried various trigger systems. But that proved to be inconsistent (messes up more often with slower speeds, for example) and held different results in different builds (Test run in the editor showed the train right on the mark, but building the level and testing it showed the train turning too much).
I even tried raw physics. I didn’t think it would work, and it didn’t; the train simply flew off the tracks the moment it hit any kind of turn or hill at any relatively high speed, no matter the shape of colliers I used.
What would you guys suggest for getting this to work? I’d really like to use the Spline curve system, but it just doesn’t seem like I’d be able to change the curves on the fly like I’d have to be able to. I tried this, but it doesn’t calculate the curve since that script calculates the curves when you connect the object to the line in the editor, not in run time.