Hello, I’m fairly new to Unity and am doing a bunch of prototyping to figure out what I can and can’t do in the engine. One of the things I’m most fascinated by is Mecanim and its ability to drive character movement via animation cues. To test out how the pipeline works, I threw together a quick model in MakeHuman, imported that into Blender, and put together a bare-bones walk cycle.
Unfortunately, when I import the .blend file (attached) the animation exhibits some odd behavior: it seems to drift to the right, very slowly. There is some hip/shoulder swing in the animation, but the start and end frame match up exactly. This problem is exhibited both when I import the .blend directly and when I first export into a .fbx. I’ve also tried various combinations of the “Based Upon” settings.
I know I could hide this specific issue by not using root transform rotation, but since I am hoping to base my character movement off of animated root transforms via Mecanim, I’d prefer to fix whatever problem is wrong in my pipeline now than have to deal with a character rotating too much/too little when I actually want the character to rotate as part of an animation.
Does anyone have any thoughts as to where I might be going wrong, or where I might find more information? Any help would be greatly appreciated, thanks in advance.
Yes, this is fairly normal, and Unity has a way to compensate for it. I’m afraid I forget the details, as I’ve given up on using root motion myself. But there is a place in the animation import process where you can preview the animation, see how much rotation it’s causing, and even get a numeric measure of this average turn rate. Then, at that same place, you can compensate by adding a little bit more or less rotation.
I learned this by going through the “Unity 4.0 Mecanim Tutorial” here. I highly recommend it if you’re getting into this stuff.
Hi Joe, thanks for the reply. I looked into the tutorial, but while it looks like there is an option to correct an animation that plays entirely at the wrong angle, there’s no way to correct for unwanted rotation delta.
I think I’m going to abandon using root motion as well, if I can’t guarantee precision in movement I’m going to want to do all this in code anyway.
Looking at it again, I think you’re right. Sorry I led you astray there.
But yeah, I found that ultimately, I couldn’t get the precise control I wanted when using root motion. It was especially problematic on turns: a turn animation may be a perfect 45 degrees when designed, but as soon as you blend it a bit with (say) the idle animation at start and stop, then it’s going to be less than 45 degrees. So, I gave up on root motion and just coded it myself, and have found more happiness.
All that said, others have used root motion successfully, or used it on only some animations but not others. I think if you’re making something like a fighting game, where the animations are quite complex and the particular angle the character’s facing isn’t too important, then root motion would be great.
Running through the tutorial (specifically, the part where you correct the poorly-looped animation) gave me an idea, which turns out to have largely fixed the problem. I duplicated all of my animation’s keyframes so that the animation plays twice before looping, and just told Unity to take the middle of the loop when importing the animation. The problem still persists somewhat, but it is much lessened, to the point where it takes several hundred repetitions of the animation for there to be any noticeable drift in the character’s orientation.
My current theory is that Unity drops a frame’s worth of root motion when looping the animation, and I only exacerbated it by somehow messing up the easing curves on my animation when making it loop in Blender.
Fortunately, now that the problem is (mostly) fixed, I should be able to go back to my original plan of using Mecanim’s root motion to implement this prototype.
If you haven’t already, try setting Root Transform Rotation > Based Upon > Original. This can help get rid of “drift.” Depending on your animation, it can fix the issue.