3
$\begingroup$

I'm trying to make a train mesh follow a curve path. The Curve modifier does this admirably, unfortunately I need to export the animation to a game engine so a modifier just won't do.

I tried adding bones to the mesh but it turns out making those follow a curve is not trivial. I copied the workflow outlined here by adding a second "helper" curve, making that one follow the path with the Curve modifier and putting a Spline IK constraint on the tail bone targeting the helper curve.

This works perfectly as long as my path is flat. Unfortunately, even the tiniest hill causes my train to flip over and do a full 360 (in direction of travel) around the track in one specific location, and I can't figure out why.

image

I tried all sorts of settings on both curves. Handles are aligned, twisting is set to Z-Up on both curves, and I added multiple Limit Rotation constraints to the bones. Nothing helps. It's interesting to note that when I set the helper curve to extrude, I can see that it stays perfectly upright when following the path:

image2

So it's only the bones rotating, presumably because of the Spline IK constraint.

Please help, I'm going bald pulling my hair out over this. Any solution that keeps the wagons upright in this setup is welcome, though I'm also open to alternate suggestions on how to get them to follow the curve in the first place. I've uploaded the .blend file so you can take a better look at what I'm doing:

$\endgroup$
1
$\begingroup$

I managed to find a solution, but it's a bit of a hack. Most notably, the process involves baking the animation, so it needs to be redone every time you want to change the layout of the curve.

  1. select every bone in the chain and make sure "Inherit Rotation" is turned OFF
  2. keyframe your "helper" IK curve to whatever you want the train to do (I wanted mine to go full circle around the curve)
  3. Add a cube or empty somewhere high up in the scene (doesn't matter what it is)
  4. make a copy of the armature/mesh in case we want to go back
  5. bake action (visual keying and clear constraints)
  6. select every bone and add a locked track constraint to each one, targeting the cube or empty or whatever you added in step 3. Fiddle with the settings until it makes your train stay upright.
  7. bake again and export for use in Unity or other game engine.

Simple, right? Repeat steps 5-7 every time you change the curve or otherwise modify the setup. I'd much prefer adding the locked track constraints without baking in step 5 to avoid this, but I simply cannot get that to work, the Spline IK constraint overrides my Y axis rotation. So this will have to do. If anyone has a better way to do this I'd be very much interested.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.