How to make a train follow a train tracks mesh

Godot Version

v4.2.1.stable.official [b09f793f5]


I have a train tracks mesh made in Blender using a curve. I need a train in Godot to follow this curve, but unfortunately it doesn’t look like there is a way to import it.

I’ve tried adding empties along the curve in Blender and then adding them as points to a Path3D curve in Godot, but the resulting curve is not smooth (I don’t know how to smooth it) and more importantly the editor starts lagging pretty bad when the curve has more than ~50 points (I will probably need much more than that)

I’m really not sure how to go about this, how do I make the train follow the tracks smoothly?

Ooh, good question! I would have tried what you did first, but if that’s not working…

If the train track is static and doesn’t change, then I would create an animation in blender with a point that goes around the track. You can see a video on how to do that here -

Afterwards, when importing into Godot, you could get the animation as well, then either have the train be a child of the point or have a script that has the train go towards the point, like it’s being led around.

I don’t know if it’s the best way, but it’s how I would approach it!

1 Like

Thanks for the suggestion, that is a pretty clever solution I would not have thought of.

I tried it but the results are not very good, the animation is jittery (could probably increase the frames per second or something to fix that) and I would need multiple points and/or animations because I have multiple train cars.
The “Follow Path” modifier doesn’t have a way to offset using distance, and I want my train to move at a specific speed, so I would have to somehow calculate the length of the curve and try to move it at a speed like 1m/s and then multiply the speed of the animation with the target speed.

I think I’ll try flipping the problem, instead trying to follow the tracks I’ll try making my own curve (maybe Catmull-Rom?) and procedurally generate the tracks in Godot.