- Home /
Mecanim Npc control
So! im using mecanim to manage some animations in a pet project im working on. just the state machine with no root motion, the movement is handled via transform
Guys i was wondering what is the best way to set Animator floats for a npc? i have been using charactercontroller.transform.forward.magnitude to tell the animator the npc is moving forward. this however seems clunky and at the moment it can only be set to 1 and never back to 0 when he is not moving.
Behold my Scripty awesomeness! Any thoughts on the issue would be great. My aim is to have a drop on defualt animator script that can detect the gameobjects movement to set Vertical,horizontal,rotation floats in the Animator. Thanks for taking the time to read this.
using UnityEngine; using System.Collections;
public class npcAnimator : MonoBehaviour {
private Animator _anim;
private CharacterController _control;
// Use this for initialization
void Start () {
_control = GetComponent<CharacterController>();
_anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
}
void FixedUpdate()
{
float v = _control.transform.forward.magnitude;
_anim.SetFloat ("Speed",v);
}
}
Your answer
Follow this Question
Related Questions
Animation Events and Mecanim 0 Answers
What is the proper way to wait for an Animator Controller to update? 1 Answer
C# Help with setting up jump animation 0 Answers
How do I use Mecanim on an NPC? 2 Answers
Problem adding individual clip speed 2 Answers