Train Driving Logic

Hello.

I’ve been experimenting with trains and I can’t seem to find a good solution for driving them so that they will follow the tracks. What kind of logic should I use for this kind of movement?

Help is appreciated.

7 Likes

Depends on what system you are using to move the trains in the first place.

Will they be cframed, using physics, body movers etc?

3 Likes

Whatever is the most efficient to accomplish this task.

1 Like

If you want them to follow the tracks no program is required you just need a force moving them and gliders to make them follow the tracks

So if you attach some spheres onto the bottom of the train like this it will work fine:

5 Likes

I’ve thought about this but what happens if there is a junction?

2 Likes

It will still follow the rails as they are a spherical shape

Just make sure they are gradual turns not sudden like this example

7 Likes

While this does work, it might not be reliable enough in some cases, and if the train is following a pre-set path it would be more efficient to use CFrame to follow the tracks. You probably want to look at this really helpful post by @EchoReaper

5 Likes

However that will lag more

2 Likes

It entirely depends on the implementation. More often than not using the method I suggested will lag less. (As I did say in my reply)

2 Likes

Programming a train to follow a predefined set of rails will not lag more than relying on constant collision solving to keep it on course, even if you are interpolating to make the ride appear smoother. Roblox physics of fast-moving trains may result in some disappointing behavior in a laggy server online.

4 Likes