I’ve grabbed the script from the Unity tutorial: Scripting Root Motion for “in-place” humanoid animations.
The script for root motion for in-place animations looks like this:
function OnAnimatorMove() {
var animator = GetComponent.<Animator>();
if (animator) {
var newPosition = transform.position;
newPosition.z += animator.GetFloat("V Input") * Time.deltaTime;
transform.position = newPosition;
transform.localRotation = Quaternion.identity;
}
}
And my player control script looks like this:
#pragma strict
internal var animator : Animator;
var h : float;
var v : float;
var rotSpeed : float = 90.0;
function Start () {
animator = GetComponent(Animator);
}
function Update () {
h = Input.GetAxis("Horizontal");
v = Input.GetAxis("Vertical");
}
function FixedUpdate () {
animator.SetFloat ("V Input", v);
transform.Rotate (new Vector3(0,h*Time.deltaTime*rotSpeed,0));
}
Why am I not getting any local character rotation? My character can only move forward and backwards. I’ll need to get my player rotating on the local axis and moving in the new direction.