- Home /
Mecanim Root Motion Rotation - 180 degree turn.
Hi.
I am currently trying to use an animation which turns my character 180 degrees on the spot to face the opposite direction (2D scrolling game).
When I look at the animation in the preview window it looks correct and turns the whole 180 degrees. When I play the animation at runtime however, it does not rotate enough (36 degrees short when it stops).
I have removed any blends from the animation transitions (thought some of the rotation could be getting blended away).
Below are two screenshots of the setup I have:
From Idle to Turn transition:
From Turn to Idle transition:
Any advice on how I could rectify this problem would be most welcome.
Thanks,
John.
I solved this problem using mecanims target matching, but it was a pain to get working right. I'd be interested to see if there is a better way
On the transition away from turning, set EXIT TI$$anonymous$$E to be the length of the clip or change the condition to not include time factor. The exit time is what (I think) seems to be causing your early animation end.
Also, Atomic means that the animation can not be over-ridden, I think. It won't help it play in full, you shouldn't need this unless you really dont want anything to interrupt the anim.
Sorry Im months late :P
This was confirmed as a bug by Unity Support and QA.
When the animation was played as a loop, the turn animation completed and turned 180 degrees.
When a transition was added, even when it was set to as close to 0% as we could get it, the animation then started to stutter based on the frame rate (low frame rate caused the animation to lose up to 50% of the total root motion).
When we submitted this as a bug to Unity, they told us the transitions are currently pretty buggy (and we have several other cases when the transitions are causing issues as well). Hopefully it will be fixed at some point soon!
The answer about target matching is correct for a humanoid rig type (which is how we fixed our humanoids) however generic rigs have no target match so it can still happen to them (but only when the frame rate is really low).
Having the Atomic checkbox checked doesn't help it play in full, however the animation should not be interrupted, so having it set to Atomic is desirable for us!
Thanks for the reply!
No probs! Thanks for letting me know about the bug
I am developing a side scrolling game and I want my character to turn exactly 180 degrees. I resolved the problem with matchTarget with targetNormalizedTime = 0.95f even if ExitTime = 1 from turn, but when I have a blend between states, matchTarget doesn't work not matter the start/targetNormalizedTime. And I also don;t use matching in transition. Did you resolved this problem (because your post is one year old)? Thanks.
Answer by EHogger · Feb 21, 2013 at 09:50 AM
Here is the way I fixed this using target matching.
rotationTarget is set to just point forward by default, and then I switch it 180 degrees each turn.
private Quaternion rotationTarget = new Quaternion(0,0,0,-7);
static int idleState = Animator.StringToHash("Base Layer.Idle");
static int turnState = Animator.StringToHash("Base Layer.Turn");
void FixedUpdate ()
{
if (currentBaseState.nameHash == turnState){
anim.SetBool ("Turn", false);
anim.MatchTarget(anim.rootPosition, rotationTarget, AvatarTarget.Root, new MatchTargetWeightMask(Vector3.zero, 1F), 0.2f, 1f);
}
}
void Update ()
{
if (Input.GetKeyDown(KeyCode.N)){
if (currentBaseState.nameHash == idleState){
rotationTarget *= Quaternion.Euler(0,180,0);
Debug.Log(rotationTarget);
anim.SetBool("Turn", true);
}
}
}
Thanks for the replies. I really appreciate it. I tried target matching but I couldn't get it to work at all. I will try again with the setup you used and see if I have any joy.
Thanks again!
Answer by Xtro · May 23, 2013 at 06:24 PM
Hi. Lowering the Fixed Timestamp in Time Settings will fix this problem. I don't know why, but I just made few tests on it and noticed that it was the reason.
I'm using 0.015 as timestamp instead of 0.02 and my turn animation is in perfect length.
Btw, if you want to alter the Time Scale for such slow motion effects, you should alter the fixed timestamp according to it.
For example if you slow the time as 0.1 instead of 1 sec, you should also set the fixed time stamp to 0.0015 to keep your animations working good.
I am not sure that will help. I have tested it here and it did nothing, which is what I expected as the Timestep only affects physics calculations and how often the FixedUpdate() monobehaviour is called, which as far as I understand, have nothing to do with the $$anonymous$$ecanim animator.
Timestep is also being used for the interpolations between animation keyframes.
$$anonymous$$y 180 degree turn animation was playing shorter than the original. It was rotating something like 150 degrees ins$$anonymous$$d of 180. Preview was playing the original 180 degree.
First, I did a step mode test. I clicked the pause button before I click the start button. Then I clicked the step button until the end of the animation. And BOO$$anonymous$$! it was turning 180 degree. When I play the game without step mode, it was still shorter than original. So I understood that it was about animation ti$$anonymous$$g.
I noticed that the problem is not about the transition length at all, because I placed only the turn animation into animation controller as a default and looping animation. There was no transition, no Idle and no other animations. When I play the game, it was still playing it shorter.
Then, I went to time settings. I reduced the Timestamp from 0.02 to 0.015 and that fixed my problem. I tried some other values but 0.015 is the best.
Now my 180 degree turn animation is really rotating the character as 180 degree.
This worked for me although I set $$anonymous$$e down to 0.001. Will this have any negative impact on anything else I'm not aware of? $$anonymous$$y quick tests didn't seem to have any issues. (I realise this is 6 year old post but mainly for co$$anonymous$$g across this through google like I did).
Your answer
Follow this Question
Related Questions
Unity 5.2: Mecanim Transition Blending 1 Answer
Root motion lost in transitions 1 Answer
How to fix this Mechanim root motion problem? 0 Answers
Mecanim animation transition 0 Answers