I have a walk cycle created and the character walks along the terrain just fine, using an Animator Controller and dragged the walk cycle into the state window since I don’t need any transitions.
I have a camera that follows the character, so I can rotate around it to see every angle to check my walk animation to make sure it looks fine in-game.
When I look at the character along it’s side, I notice that there’s this quick forward shift and then back again with every step. If I check ‘Bake Into Pose’ in the ‘Root Transform Position (XZ)’ the animation is perfect and the forward shifting is gone, but the character doesn’t move forward, just in place. I tired a variety of combinations within the screenshot, but I can’t seem to correct the problem.
I see that the “loop match” is in red, so maybe my animation that I imported is where the problem lies. I created the animation is 3ds max, and choose ‘Walk On Line’ when I exported it. If I selected ‘Walk In Place’ and drag the animation into the state window the character doesn’t move forward, just loops.
Loop match is red because the X or Z position is not the same at the end as it is at the start. If your animation is set up correctly, this is a linear motion that Mecanim uses to drive the character in that direction. By Baking it into pose, you are telling Mecanim to ignore any movement on the X and Z axis resulting in an “In place” animation. If you are looking at the animation that is not baked into pose in the inspector, it will move forward with the animation and jump back to the origin when it loops. That is how it is supposed to look (or at least that is how all my animations look and they work fine). If it is moving forward and then jumps back at runtime, you have something that is adding forward movement ON TOP of the root motion.
That makes sense, thanks. Any thoughts on how to correct the forward shifting problem? Do you use max? If so, how do you export your animations; Walk on Line or Walk in Place?
No, sorry, don’t use Max. If my animation doesn’t already have forward root movement, I add it by moving my root (which is the hip of my figures) forward in the final frame of the animation (first clearing any other keyframes the root may have along the Z axis just to make sure it doesn’t walk in place until the final frame and jump). You can also temporarily turn it into a Legacy clip and look at it in the Animation tab inside Unity. Open the root transform and check out the Z axis to make sure it has a smooth transition. If it suddenly jumps, there is probably something wrong with the animation.
Have you checked out all the mecanim samples? in Theory any of those walk/run animations SHOULD work on your figure. Try one of those then replace it with your animation if everything looks more or less fine.
“Loop match is red because the X or Z position is not the same at the end as it is at the start.” - How can the root bone be in the same position at the end as at the beginning? After all, this is the point - Root bone in animation from the zero position at start goes to other position at end of the clip. This is how movement in the character’s space is obtained, isn’t it?