- Home /
Using root motion scripting for specific animations
I have various animations from the asset store which I intend to use within my game, currently I am looking to introduce some combat stance animations. All my current general movement animations are within an animator using Mecanim and they all have root motion in-built, i.e. they have velocity and the animation causes the character to move across the map.
I have imported some new combat based animations which were originally set to Legacy, I changed them to Humanoid for use in the animator but they have no average velocity, i.e. they are in-place animations and don't make the character move. I understand that to make these move the character I need to attach a root motion script and call OnAnimatorMove to set the characters transform based on the animator parameters.
The problem I'm facing is that this affects all my animations, is there a way to only use this script for the specific in-place animations but use default root motion for all the others that work fine?
Thanks in advance.
Did you ever get an answer for this? I was about to answer, then I noticed the date it was asked.
Answer by moxiewhimsy · Apr 05, 2015 at 06:16 AM
One way to do this is to implement your own Root Motion handling script.
Start by figuring out which animations you want to use the built in root motion, and which you'd like scripted motion. You may wish to add curves to the animations you'd like scripted, to provide animation-matched data for use in your script, but this isn't always necessary.
Then implement an OnAnimatorMove() method in a component script with access to your Animator. Note: Once you do your object's Animator component will print "Handled by Script" in the Apply Root Motion field rather than allow you to toggle it via checkbox. Within the method, you can implement any scripted motion you like. For any built in root motion you'll need to grab it from the Animator (deltaPosition, and deltaRotation will be useful) and apply them directly to the root (Transform) of your animated object.
You can mix scripted and built-in root motion, but it may look very weird if you alter the interpretation of the built-in motion curves.
Your answer
Follow this Question
Related Questions
Can i use mecanim animator while using legacy? 1 Answer
How to fix this Mechanim root motion problem? 0 Answers
Moving Character to exact position using animation. 0 Answers
[Unity 4.3] Skinned legacy animations do not work 1 Answer
How to use mecanim to play specific animation clips when public static int condition is reached? 2 Answers