Animating a Railroad

Howdy, i’m modeling a largeish scene in a realistic steampunk steel mill, with a moderate outdoor portion, and trains are a moderate focal point. Small steam engines service the furnaces with slag trains, scrap hoppers, torpedo cars and ladle cars, while outside large PRR style engines haul freight and factory parts down the brick and steel corridors to sell the place as a live factory and mill, shipping out all kinds of stuff around the clock.

And i was hoping that someone here would have some experience or advice on what the best way to go about trains in general is from the outset, particularly how to handle multiple cars going down the track with canned swaying and running animations, bogies and couplers correctly pointing ahead to the next car and following the track at least passably well. I’d prefer that individual cars are separate objects, i already did some basic construction script stuff to make the numbers and wear picked randomly from a pool every time a car or engine is drawn up, so having any train as a single canned entity really would throw a wrench in the works as far as that goes.

The basic plan i have now is that each car has bones for each bogie and coupler, and another for the main car itself, positioned over one bogie. The bogies travel along and point forward towards the track’s spline/curve and the car body is parented to the rear bogie and points forward to the front bogie. The couplers parent to the car body and track to the next/previous car’s coulpler, which is the setup i have in blender for animating trains.

Trouble is i’m pretty new to unreal and not entirely sure that this would fly very well even in pseudo realtime, so i figured before i jump headlong into things and start hamfistedly trying to make that work, i’d see if anyone has any experience or pointers for such a thing.

You can animate the train in Blender and then bake out the key frames to the bones via FBX. This way if you use fancy controllers and spline paths the translation data is transferred directly to the bones as absolution animation data.

That’s what i’m trying to avoid though, to keep it as in engine and modular as possible, and so each train rolling by doesn’t have to be a dedicated asset for just that particular train

Well what you have outlined should be a good starting point as to how complex you need the final result. The trick as I see it is not in how the train and cars are set up but how to connect then to the tracks.

I’m not up on slines in Unreal 4 but in 3ds Max you can attach an object, or bone, to a spline and it can be animated as a parentage of the total path to follow so it’s a relatively simple procedure and really more about what you want to do with the result.

Is this a project you need to pass on, give away for others to use, or to sell on the market place?

Top down design requires a purpose of which a design needs to serve and not just that it works for a given or unique requirement or specification.

I would say go with what you know so in this case your concept is sound and can be easily animated procedurally with out keyframes and the magic trick is connecting it to a dolly(s) as part of the track rigging.

Of interest the Showdown has a few good examples of static objects constrained and animated to splines so maybe check that out. Instead of rockets think of them as trains. :wink:

I was thinking about this some time ago. It shouldn’t be difficult as long as you find a way to calculate intersection of spline with circle:

Yellow is a cart, dark blue is leading bogie and cyan is trailing bogie. First you calculate position of leading bogie along the spline from it’s speed, intersection of circle with spline will give you position for second bogie.

Edit: didn’t had time to elaborate on finding intersection. The straightforward way is to iteratively approximate spline with the set of line segments and look for intersection on each iteration. Reiterate until you reach some necessary precision. The amount of iterations can be scaled by how much curvature you have at spline.
Another approach is to take two control points and find intersection of circle with line between them. This will be your x for the Bézier curve, from there you can calculate y of the spline as you know tangents from control points. I would do the later but I don’t know which specific formula engine used to draw them.

Just thought of even much simpler solution. Animate all bogies independently, make sure that when ever you change speed of the train, bogies which belong to the same cart should have exactly the same velocity along the spline. This way they will move at exactly the same distance along the spline and you are golden. Any numerical inaccuracies which will build up over time can be solved by running train on a straight piece of rail ones in a while and re-aligning bogies to each other. Otherwise they should separately at more or less exactly the same distance all the time.
Unfortunate part is that all this solutions remove possibility to use physics. In case if you want physics then you have to imitate friction with rails, which is a bit different level of simulation :slight_smile: