Hi guys, so I have a character setup, and the parent object it’s actually an empty game object, consist with the character model as a child in it. And all the scripting are on the parent object (moving, jumping, edge grab, etc). The problem is, the edge climbing animation are using root motion to translate across the Y-axes, but because the mecanim character is the child object, the Y position snaps back after climbing animation is done. Is there a way to apply the climbing root motion to the parent object?
Thanks a lot for the help, a little question though, that script should be attached to the child object right(the mecanim character)? not the parent object(emptyGO)…I’ve tried it but it doesn’t working…
Yes, the object that has Animator, I think you didn’t select good root bone in import settings. If there is root motion your object shouldn’t snap back after climbing animation is done.
I’m using 3dsmax biped FYI, and I’ve set the root Bip as the hips as well pelvis as the hip, and still not working. Under the import setting animation tab, the only animation that bakes root motion Y is the edge climbing, could this be an issue? And after I added the script above, under Animator, the option apply root motion is handled by script…
I’m new with mecanim by the way, so I may be doing this the wrong way…
Yay, it is working now, I’ve unchecked the root transform position Y for the climbing animation and that seems to be the problem. Now the parent object follows the mecanim character nicely upon climbing…Thanks a lot for the help Aniv!
Here I post the code I’m using (just a slight modification from aniv snippet, I’ve added the x root motion into account), in case someone needed the code:
using UnityEngine;
using System.Collections;
public class AnimatorMove : MonoBehaviour {
void OnAnimatorMove() {
Animator animator = GetComponent<Animator>();
if (animator) {
Vector3 newPosition = transform.parent.position;
newPosition.y += animator.deltaPosition.y;
newPosition.x += animator.deltaPosition.x;
transform.parent.position = newPosition;
}
}
}