Turning on/off root motion in script?

Hi there,

Not sure if I should post this here or in animation but here goes.

Is it possible to turn root motion on and off using script? If so, preferably explain in C#, cus that’s what I am using.

The reason I want to do this is that I would like to make a character use root motion when running. But when jumping I just want him to be controllerd by gravity and upward velocity. making the jump height easier to tweak.

bump

I’m also trying to toggle Root motion on/off in script. As the doco says, if OnAnimatorMove is implemented, it has no effect. http://docs.unity3d.com/Documentation/ScriptReference/Animator-applyRootMotion.html

If anyone knows how to do it otherwise, I want to know.

Yeah, just have your script set the animators applyRootMotion property as required.

Bump. Setting the boolean applyRootMotion if you have OnAnimatorMove implemented does not work. Is there no way to toggle between root/non-root motion at runtime? This is pretty important

Hey, I don’t know if this is correct for what you guys want but I’m just messing with root motion now and i’ve just done “animator.applyRootMotion = false;”

At the top of the script i’ve done “private Animator animator;”

in the start function i’ve done “animator.GetComponent;”

and in the update function i’ve done “animator.applyRootMotion = false;”

so that was just to test if I could turn it off or not, so Now if I wanted to do a collision to deactivate root motion or anything i’d just use the line " animator.applyRootMotion = false; " within whichever function i wanted so lets say for example

"
Void GettingInTheCar () {
If (GetInCar) {

animator.applyRootMotion = false;
}
}

so then in the update function i would write

GettingInTheCar();

and that would call the function (You probably already know this) and well obviously whatever proper function you wanted to do would/should work the same… Just an example, Works for me but I might be trying to do something else entirely lol…

2 Likes

In case anyone has this issue, the correct way to do it is to use Animator.deltaPosition and Animator.deltaRotation and apply them to your transform thusly:

transform.position += animator.deltaPosition;
transform.rotation = animator.deltaRotation * transform.rotation;

Then the root motion position and rotation will be applied.

2 Likes

Works perfectly! Thanks!

1 Like