- Home /
Using Mecanim Animator to move Model Left & Right
Hopefully this will be specific enough, but I've recently gotten into Unity and have been messing around with Mecanim in Unity (free version) to try and get some simple things up and running. So I have these blend trees for Locomotion that moves the character around based on the float value of speed, transitioning between the two for walking or running forward. When these activate my model does indeed move forward and successfully blends through these two states like it's meant to, then with a Direction value of float, I get it to move between the different states of running and walking (run, run left, run right etc) however unlike running and walking, when the animation transitions into these different states, the model doesn't move right or left it continues on a forward path while leaning right or left instead.
I was wondering if there was something fundamentally wrong with what I was doing with the trees and maybe I'm supposed to be using this in conjunction with some code to make the character move right or left, but any help would be appreciated.
Player movement code: using UnityEngine; using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float turnSmoothing = 15f; // A smoothing value for turning the player.
public float speedDampTime = 0.1f; // The damping for the speed parameter
public float movementSpeed = 1f;
private Animator anim; // Reference to the animator component.
private HashIDs hash; // Reference to the HashIDs.
void Awake ()
{
// Setting up the references.
anim = GetComponent<Animator>();
hash = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<HashIDs>();
}
void FixedUpdate ()
{
// Cache the inputs.
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Debug.Log ("HORIZONTAL: " + h);
Debug.Log ("VERTICAL: " + v);
anim.SetFloat (hash.speedFloat, v);
anim.SetFloat (hash.directionFloat, h);
}