- Home /
How to control step distance for root motion (Mecanim) animations?
I have become quite comfortable with the legacy animation system and will now be making my first attempt at the mecanim way of doing things.
One of my first issues while using root motion is getting a consistent step distance or overall movement speed for characters of different scales. For example, the player avatar will have slightly customizable size (scale). Also the enemy characters will have a script attached which will randomly choose a size (within a range), so that all of the enemies are not the exact same size by default. With root motion however, the larger characters have a larger step distance and therefore move faster than the smaller ones.
I would like to be able to control this, similar to how in the legacy system you can set a specific speed. For example, if I need all characters irrespective of size to move at the same speed, or the larger characters may need to move slower than the smaller ones since they are more heavy.
Apart from changing the animation speed, is there a setting in the animation properties or a way to do this via script in mecanim?
Answer by Prefab · Jul 03, 2016 at 05:23 AM
Based on my research it looks like that the only way to do the above at the moment is to set the specific animation to loop in place, and then override the root motion via script. This can also be used for other distance based animations such as jumps, dodges etc in which you need precise control over the distance traveled, or if this distance needs to change at runtime (based on stats for example). Here is the link to the documentation that covers this: http://docs.unity3d.com/Manual/ScriptingRootMotion.html
Answer by Nazirzadeh · May 06, 2016 at 11:43 AM
If your problem appears after resizing the objects: You should add your original gameObjects(Avatar,...) as a child of an empty game object. Then change the size of the parent gameObject. In this way everything should work fine.
I am not quite sure how parenting a character to an empty should change the distance of each character's walk step, or the overall walk speed. I have tried what you suggested and it makes no difference as far as I can see. Could you please explain this some more.
Oh, Sorry you can reduce the speed of playing animation in Unity3D or you shoud try procedural animation in Unity3D.
I prefer to solve this kinds of problems in maya or other tools by animateing each character based on its size and desired speed.
Yeah, unfortunately because the player size will be user customizable there are too many variations to try to resolve this at the modelling level. I have tried adjusting the animation speed in proportion to changes in character size, but visually this ends up looking a little silly. I may have to simply keep using legacy animation ins$$anonymous$$d.
Your answer