Root Motion Computer for Unity

I recently finished up a new component for Unity as part of a contract job with Mixamo. For those of you who are unaware, Mixamo provides an online motion capture download and retargeting service powered by HumanIK. It lets you use sliders to creatively adjust a piece of motion capture data and then automatically retarget it onto your own hierarchy and download it for use in your game. It’s really slick and pretty affordable, so it’s definitely worth checking out, particularly for any indie developers out there.

At any rate, the component that I created is designed to let animation data, rather than procedural velocity values, drive a character’s motion in space. The component sits on top of Unity’s animation API to let you simply play, crossfade, and blend animations using any of the existing API methods, and the computer takes care of everything else after the fact. The way it works is by tracking the position and rotation of the pelvis in the space of the character’s root node for each active AnimationState and then backward applying this motion to the root node itself and snapping the pelvis back into its position hovering over the root. Since the source code is all available in the project, I won’t belabor the details too much here, but you can certainly ask me if you have any questions. (The one thing perhaps worth mentioning, as an addendum to the video, is that the pelvis forward axis is not strictly necessary for computing output: only for displaying debug information. For computation, the character’s rotation is determined using the pelvis right axis.)

You can download an example project from Mixamo that contains the component as well as a sample character with some animations. Because the tutorial video on the Mixamo website is compressed pretty substantially, I have also uploaded a copy to my Vimeo account in case you would like to watch it in full HD resolution.

Tags: , , ,

18 Responses to “Root Motion Computer for Unity”

  1. [...] Mechtley demonstrates the Root Motion Computer component he created for Mixamo for use in Unity projects. The component is designed to let animation data drive a character’s motion in space as an [...]

  2. David Koontz says:

    Wow Adam, this is a very impressive bit of code you have here. I had dabbled with Mixamo before, knowing you’re helping them put out awesome tools pretty much seals the deal on where I’ll get animations when I need them. Rock on man.

  3. Adam says:

    Good to hear from you, David! I’ve been quite happy with the animations I’ve gotten from Mixamo so far; it’s really helped speed things up. Hope everything is going well for you and your family!

  4. I’m late to the game in finally tracking this down but thanks for this tool! Awesome stuff!

  5. [...] Totally awesome tool for Unity: The Root Motion Computer [...]

  6. stringa says:

    Hello.

    I would love to have a way to contact you about this. I have 3 animations blended on top of each other (layers 0-2), where layer 0 is all the translation needed to calculate the pelvis movement.

    Layers 1 and 2, run mixingTransforms…above the pelvis. Basically, I have a character which walks and idles on layer 0, layer 1 blends vertical rotation…and layer 2 does a reload animation.

    The script really doesn’t handle this case. It seems that it can’t handle mixingTransforms…cause it just is looking at blend weights.

    I know this is the issue cause when I comment out layer 1 and 2, the rootmotioncomputer works, and putting them back in, breaks everything…

    stringa

  7. Adam says:

    Hi Stringa,

    Sorry I never noticed this comment. I actually talked about this during my Unite presentation. You can view it on the Unity website here: http://unity3d.com/support/resources/unite-presentations/character-animation-workflows

  8. Alonso says:

    Does this script work on 3ds max bipeds exported to Unity?, I try, but it seems not

  9. Adam says:

    Hi

    It absolutely should. Can you be a little more specific about the problem you’re having?

  10. Alonso says:

    Ohh sorry, it was my fault, With a biped imported from Max the Pelvis is Bip001 and the root node are the top most object of the hierarchy, and the pelvis right axis is (0, 0, -1). Hope this tip help for 3ds max biped users

  11. KOSAKA Jun says:

    I’m sorry for my poor English.
    I attached ”Root Motion Computer” to my bone animationed character .and worked verry well!
    This is very good source.
    But when I changed the Scale of the character ,the moving distance of root bone is original length.
    Other bones are working as a changed scale.

    I think I remake the charactor in the 3D modeler ,it will work good.
    But I want to change the scale of my character dinamicaly by Scripts.

    If you know the solution of this problem,Please tell me.

    best regard.

  12. Adam says:

    Hi,

    Depending where exactly the RMC object falls in your hierarchy and what you need it to do, you can do something like this before the call to rootNode.Translate()

    dPosition.x *= rootNode.localScale.x;
    dPosition.y *= rootNode.localScale.y;
    dPosition.z *= rootNode.localScale.z;

    You can optionally use lossyScale if it makes sense for what you need to happen.

  13. KOSAKA Jun says:

    Thanks a lot !!

  14. Ted says:

    Hi Adam, fabulous contribution to Mixamo and community at large. I’m still getting my hands wet with character animation to add to my indie game. Does the RMC only work for Mixamo characters and animations? I plan to use those, but I also tried to apply RMC to the free Spartan King character w/animations from the Unity Asset Store. I hace him animating fine, but RMC does not apply motion to his CharacterController. The vector displacement ends up being zero no matter which animation is running. Hoping you might have some helpful suggestions. Thanks.

  15. Adam says:

    Hi Ted. The RMC works with any character, not just Mixamo characters. It basically requires that you set it up properly, and that the character was animated with root motion applied to it. I’m not familiar with the Spartan King character, but it sounds like maybe he has in-place animations, rather than animations where he actually moves forward.

  16. Ted says:

    Adam, what’s your email so I can message you privately? Can’t find it on your site. Thanks.

  17. paperab says:

    Hi,

    You did a great piece of software.
    I have a question: are the animations needed to be move forward ? Because I have a bunch of in place animations which seems do not work. The GO is not moved (exported in this way from 3ds Max).

    So my question is: what kind of animations are required? Moving forward or in place ?

    Thank you !!!

  18. Adam says:

    Hi! The Root Motion Computer is intended to used with animations that move forward, not in place.

Leave a Reply