Created
November 21, 2015 23:21
-
-
Save DanBrooker/37e65be2f872278d188f to your computer and use it in GitHub Desktop.
Unity 5 Mecanim Legacy Animation, Adds root motion using animator Forward
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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