Override root motion z-rotation in Mecanim

Hello!

I’m using an animation which I haven’t created.
As you can see here, the animation makes the model drift to the right over time:

In my game, the model is steered by a MeshNavAgent and root motion. I’ve set the MeshNavAgent’s speed to 0.001 so that the motion comes to 99.99% from the root motion of the animation.

It works fine, but the NavMeshAgent seems to take the rotation (and - to my observations - also the z position) from the animation, so it rotates my model more and more to the right.

Here is a video:

I was thinking that I should just disable the z-rotation and z-position of the animation.

However, I haven’t found any working code that would let me do that.

My code approach is this (it’s a script that is attached to the NavMeshAgent):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Agent : MonoBehaviour
{

    public Transform target;
    private NavMeshAgent _agent;
    private Animator _animator;

    // Use this for initialization
    void Start()
    {
        _animator = GetComponent<Animator>();

        _agent = GetComponent<NavMeshAgent>();
        _agent.updateRotation = true;

    }

    // Update is called once per frame
    void Update()
    {
        _agent.SetDestination(target.position);
    }
}

Could anybody help?

Thank you very much!

You could disable the root motion on the character in the animator for the character and then control it’s root motion with its transform via code. Or you could take the FBX out into a proper animation program and edit the curves of the root joint animation to just have it transform directly forward in Z.

Check out my WIP
https://forum.unity3d.com/threads/3d-platform-3rd-person-character-and-camera-system.469274/#post-3056053

@RevoltingProductions Your controller looks really nice, thank you for the demo.

@RevoltingProductions When I disable RM in the animator, would I still be able to apply exactely the same root motion via code?

@twda You know what, now that I look at that animation I see that it has an uneven, lurching movement. So there are a few ways that you may be able to deal with that. What I said before about turning off root motion is wrong. Sorry, instead keep root motion on but in the inspector for the asset that has the animation, go to the animation tab and at the bottom you will see a menu item called “motion”. Under that will be the joint you are deriving root motion from called whatever the root motion bone in that rig is called (probably root). Switch that dropdown to “none”. Then apply. Once you do that it will populate a more complex system for extracting just the movement you want. You can specify which root motion channels you want to be factored. Turn off X and just get root motion from Z. That should fix it.

1 Like

@RevolingProductions
Thank you. “Motion”->“Root motion Node” was already at “”.

I played around with the “Root Transform Rotation / Position”, but I never got good results.

I’ve recorded a video of my attempts here:

Do you perhaps have any other suggestions for me?

@twda Sorry for the incredible delay. So did you actually turn the channels off? I didn’t see that you did that in the video.

Anyway if you are still having problems just post that FBX somewhere and I’ll fix the animation for you. It would only take a few sec.

@RevoltingProductions

Yes, I tried anything.
I have uploaded the animation here: https://drive.google.com/open?id=0B-Er2CFKxClOYTJMV2tUWGpwRDQ

Thank you so much!

I would so much like to see what you do to fix this. You won’t record a video of your editing, won’t you?