Root Motion not having gravity (while Animate Physics turned on).
I'm using Root Motion Animation on a (rig-less) cube.
But my animations --even with "Animate Physics" turned on-- seem to ignore gravity.
When ever I jump (rb.AddForceAtPosition) while the Animator is in Idle state; my cube starts to float.
I found some posts explaining bugfixes like "GravityWeight" should be set to 1 by adding a 'curve' to the animation ...but since I use a 'custom' Unity Animation, I cannot add a 'curve'.
I also tried setting Animator.gravityWeight to 1 through script... but it seems a read-only function. And the result I 'get' from it is unsurprisingly: '0'.
I'm getting a bit desperate here, why isn't my root animated cube using the gravity? And if GravityWeight is the true fix, how could I apply it to my (not imported) Unity Animation?
Answer by Paolofix21 · Mar 11 at 08:53 PM
I'm not completely sure that using the Animator's physics makes sense considering what you're trying to accomplish.
The animator's root motion is meant to be used when having to do complex motions (i.e. non linear, nor uniformly accelerated). Moving a cube is a really simple thing and using an animator is definitely overkill.
A better solution would be to handle the cube's movement through script directly.
Possible solution
Anyway, since we're here, if you really want to use an animator for your movement you might want to check a few things out:
When using the animator's physics, if you want to move the rigidbody you might need to handle some logic inside the OnAnimatorMove() method on a MonoBehaviour.
Learn about the StateMachineBehaviours
Regarding the "GravityWeight" parameter, you might need to uncheck the field Write Defaults on any State of the Animator that you don't want to allow modifying your gravity.
Unfortunatey I can't help you more since using the Root Motion on a non-rigged object is an approach that I've never used.
Thanks @Paolofix21 , I know it doesn't make any sense at first, but I want to be able to add subtle shakes, flinches or rotations, which I cannot script. Also the cube never lays on just one side in this case. So it would be great to have a function that just handles up/down etc with characteristic movement details no matter what way the cube is rotated/positioned.
Unchecking Write Default doesn't do the trick unfortunately. Just tried.
It's just weird right?; whenever I put the Animator on my object, gravity doesn't apply to it anymore, at least not in a normal way... I will have a look at the OnAnimatorMove() method, who knows what it might bring! Thanks again.