- Home /
MecAnim Root Motion - How To Prevent It
Hi folks,
NOTE! I solved my own problem as I was nearly finished writing up this question. I'm going to post the question anyway (with my answer at the bottom) in case anyone else comes across this. I'm officially embarrassed once you see what the solution actually is.
I'm just getting started using MecAnim so there's plenty of learning to be done. It's absolutely amazing but I've hit a problem I can't seem to get around, and I assume it's just because I'm doing things incorrectly.
We have a scene where we want our character to be idling in a different position within the scene randomly when you enter the scene. The animations have his position in the scene built into them. So if I set an animation state within the Animator window to default that has him, say, sitting at a desk in the room, he'll be there. It works great when I default to that.
The problem comes in when I attempt to have a starting default node that's empty, with a series of transitions that lead to actual animations. I have a parameter called DesiredState, which I default to -1 within the animator window. When my script starts, I randomly set it to a valid value, which takes us from the Default State (which is just an empty state with no animations) to the appropriate idle. He'll play the idle animation, but he seems to only get 'some' of the root motion, and I don't fully understand why.
My tree is looks like this, where each Transition arrow is just checking if the desired state is whatever we want it to be (for instance, laying down you can see I use [ 2 ] so a value of 2 would transition us to that state).
The STARTING STATE is my default, as you can see...and if I set '[ 2 ] Laying Down' to be default, he'll be there fine. But like I said, if I try to transition to that state, he'll be playing the laying down animation, and he'll correctly be up on the Y axis (the cot he sleeps on is above on a platform) but his X/Y position are wrong.
Specifically, when I go into this scene and see he's wrong, all I need to do is zero out his position. The X and Z actually get values, which are wrong! I want him to be a world origin because we place him within the animation. The Y value is 0, which is what it should be, because the animation places him up high on the cot, but the X and Z are getting values and they shouldn't be.
One of my animations looks like this:
I'm going to skip the wrap-up (this is when I discovered the solution) and simply mention what I missed so other people can save themselves a few hours of hair pulling.
MecAnim offers a ton of power and flexibility, and while you might think it all exists within the Animator tree and the animation clips themselves, there is ONE option I missed that sits on the Animator component itself. Since we were positioning our character through the animations, ultimately, we didn't want Root Motion at all. Well, there's a checkbox for 'Apply Root Motion' right on the component. If you don't want root motion, uncheck that and keep a full head of hair!
Hope this doesn't waste anyone's time reading it since the solution is super dumb and likely something you all already know. But if it saves 1 person a headache, then I'm glad I'm posting.
Good luck everyone! MecAnim is amazing, enjoy it! :)
-Matt
You just solved the issue I've been stressing over for the last 2 hours, literally. I feel like such an idiot now. Thumbs up for you, sir!
But if it saves 1 person a headache, then I'm glad I'm posting.
You got your one person :P (Probably more actually)
You need to write an actual answer so we can conclude this QA. Else its just a Q.
in your experience what is it easier to work with root motion or without root motion. I am currently building a 3d side-scroller game, if i could get some perspective it will be great :)
You just saved another person from a headache! Thank you for posting :D
Yes - but for me this doesn't work - the character just simply stands still and walks on the spot. Any ideas how to rectify this?
If I got to the import settings of the animation it says "Root $$anonymous$$otion is controlled by curves" - anyone have any idea how to proactively apply gravity?
Answer by infinitypbr · Jan 24, 2016 at 02:27 AM
"Well, there's a checkbox for 'Apply Root Motion' right on the component. If you don't want root motion, uncheck that and keep a full head of hair!"
Answer by Jacooboo · Sep 15, 2017 at 08:05 AM
What is root motion doing? I mean what is root motion.