- Home /
Mecanim/Animator Controller and 8 direction movement
I am making a top down RPG in 3D mode with a scrolling, rotation-fixed camera, Zelda/Pokemon style. As Unity's animation controller is now legacy, I decided to make the switch to the Animator controller instead. However, it's been a while since I've scripted, and I'm having a bit of difficulty getting my player's walking animation to play in all eight directions of movement, and all the tutorials I'm finding online are for behind the back, 3rd person shooter controllers.
I have been able to get my player to transition from the Idle to Walking animation when I hold down the Up or W key, but all other directions switches the animation back to idle, so my player is sliding along the floor. I have tried calling multiple axis in the animation script, but when I do that, the game only reads the axis referenced last, and ignores the ones before it. Here's my animation script. I have commented out the lines I am either saving for later implementation or have failed to work.
How do I get my player to play the walking animation in all directions of movement?
using UnityEngine;
using System.Collections;
public class Walking : MonoBehaviour {
private Animator anim;
int jumpHash = Animator.StringToHash("Jump");
private float vert;
private float hor;
void Start() {
anim = GetComponent<Animator> ();
}
void Update () {
vert = Input.GetAxis ("Vertical");
anim.SetFloat ("walk", vert);
//if (Input.GetButtonDown ("Jump"))
//{
// anim.SetTrigger (jumpHash);
//float vert = Input.GetAxis ("Vertical");
//float hor = Input.GetAxis ("Horizontal");
//anim.SetFloat ("walk", vert);
//anim.SetFloat ("walk", hor);
}
}