Skip to content

Instantly share code, notes, and snippets.

@DanBrooker
Created November 21, 2015 23:21
Show Gist options
  • Save DanBrooker/37e65be2f872278d188f to your computer and use it in GitHub Desktop.
Save DanBrooker/37e65be2f872278d188f to your computer and use it in GitHub Desktop.
Unity 5 Mecanim Legacy Animation, Adds root motion using animator Forward
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class RootMotion : MonoBehaviour {
public float runSpeed = 10;
void OnAnimatorMove()
{
Animator animator = GetComponent<Animator>();
if (animator)
{
Vector3 newPosition = transform.position;
newPosition += transform.forward * animator.GetFloat("Forward") * runSpeed * Time.deltaTime;
transform.position = newPosition;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment