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:

alt text

From Turn to Idle transition:

alt text

Any advice on how I could rectify this problem would be most welcome.

Thanks,

John.

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);
				
			}			
		}
	}

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.