How should I guide a train around corners and tracks?


To begin, I have always wanted to have an AI train system which will stop at a station, open doors, wait a while, close doors, blah blah. I have never gotten around to doing this because I don’t know how to make the train itself move without wheels. Wheels can be glitchy, get stuck and make the train unstable / pushable. I found an old Devforum post from around 2020 where somebody claimed you can use BodyVelocity which has now been removed. I have tried the new LinearVelocity and other forces but the closest I’ve gotten to a working train is LinearVelocity however when the train reaches a corner, it eventually gets stuck as the velocity wants to push it sideways whereas the track is guiding it forwards. BodyVelocity would keep in-line with the body itself so the train would happily follow tracks. I don’t have much knowledge with using these new forces and velocity’s so if anybody could give some advice on how to do this, feel free to!

Some images showing my test train model:
The red circle shows where it tends to get stuck at too much of an angle:

My test train uses spheres that act as gliders which go through square pipes (rails) which “Guide” the train where to go. If I should also change the design of this, feel free to let me know!

Any help and advice would be amazing!

As long as you are using an attachment instead of “World” for “RelativeTo” the linear velocity should turn with the attachments. I would recommend putting one attachment at the front of the train and use that as attahcment0. Make sure the train isn’t getting stuck because of the wheels and rails.

That seems to work a lot better however the train gets quite shaky, could this be something with my tracks or maybe the speed of the train? It also likes to derail after some time despite the tracks fully surrounding my gliders:

Edit: I also just moved the attachment to the front and well…

LOL! yeah it is probably set to too fast. the VectoryVelocity controls how fast you want it to go MaxForce is how quickly it can get to the VectoryVelocity, if max force is lower it should be less jittery

Ah well I’m guessing infinite is too high then XD.

1 Like

Should I maybe try a different approach to this such as scripting? Roblox physics aren’t the best and my train derails very easily despite being surrounded completely by rails. I would like my train to go nearly 2.5X faster than what is is at the moment.

1 Like

I notice you moved the thread and replied to me earlier, so I’ll elaborate how you might get started with the “invisible waypoint” approach.

The most basic approach: put the waypoints on corners you want the train to turn around. Ensure your train does not collide with the rails and is suspended with AlignOrientation and AlignPosition. You may wish to suspend them above a smaller, invisible block and move that block instead, for an extra degree of control.

For the script, try this:
Generate a table of waypoints. For example, you could take your invisible markers and put them in a big table. Have a counter, that starts at 1.
In a loop of some kind, check if the train’s position (i.e. the center of rotation) is close to the waypoint in your table that your counter is on. If the distance between the two are, for example, within 30 units, increment the counter by 1. If not, move the train towards the waypoint your counter indicates.
When the counter reaches the length of the table, you have reached the end of the loop!
Making sure your train has an appropriate travel time could be difficult, but it may be possible to use tweens or a property in AlignPosition.

This is probably the most basic approach I can think of!

If you want to do something more advanced you can look into Bezier curves, but if you’re new to scripting that will be challenging.