It’s probably been done before, but I didn’t see much in regards to animating it.
I’m quite new to Blender, yet did enough research to figure this much out. Basically I set up a train constrained to follow the same path as that used to guide replicated rails. That’s not quite right… Actually it’s the bogies or wheel trucks that are constrained to do the path following, and the cars are rigged onto them. (Otherwise it gets weird in tight turns.) The result looks realistic enough.
In this test video, the wheels are solid with no texture. So I didn’t need to animate them.
That’s ok, but I think it would be neat to have wheels that obviously roll along the track… (Which would also be useful for animating drive wheels and all the associated linkages on a steam engine.) So I did another attempt using what seems to be a common method to animate wheels. I decided to keep things simple while testing this aspect, so only did the wheel truck by itself.
The method that often is used to animate wheels is having a location to rotation transform, but as you can see (at the end) it fails when going around a turn. So it’s not much good if the wheels lock up when the railroad has a curvy path. (Originally I thought it was a bug, until somebody at the Blender IRC channel explained how such transforms work in better detail. Pretty much a linear vector kind of thing.)
So I came up with a tad convoluted driver based method to deal with that problem. (Excuse my noobishness, as I’m sure there’s a bit. And my math might not be perfect either - likely omitted some stuff needed for scaling wheels to different sizes.)
It works well, but it’s still not entirely ideal.
The process of figuring out how long a path is can be a bit tedious, but it’s necessary for good animation of wheels that roll without slipping. When asking around to see if there’s a better way, somebody pointed me to a very useful add-on that performs a fairly basic function that somehow was omitted from the curve properties. I believe it’s called “Object get path length”. So when I get around to doing some more tests in this regard, I’ll be using that. (Calculating path length manually is a bit awkward and slow, and the plugin is faster with more accuracy.)
Eventually my goal for these tests is to have a semi-realistic old fashioned steam engine travel around some meandering and occasionally crazy railroads.