- Home /
Walk animation on horizontal or vertical input
EDIT: Solved. See my comment below
Hey all. I want my character's walk animation to play when I have either horizontal or vertical input... So far I have it working only for vertical input. How can I achieve this?
void Update () {
vert = Input.GetAxis("Vertical");
anim.SetFloat("walk", Mathf.Abs(Input.GetAxis("Vertical")));
}
In cash anyone else is looking for the answer to this, I found this awesome tutorial that explains how to set up your walking animation with blend trees: BLEND TREE TUTORIAL
It even works with Joysticks, and you can blend between walking and running animations as well depending on how hard you tilt
Answer by MT369MT · Jun 07, 2018 at 04:57 AM
Hi, try with this:
if (Input.GetAxis("Vertical"))
{
anim.SetFloat("walk", Mathf.Abs(Input.GetAxis("Vertical")));
}
else if(Input.GetAxis("Horizontal"))
{
anim.SetFloat("walk", Mathf.Abs(Input.GetAxis("Horizontal")));
}
I don't think that will work because you cannot use floats as bools... maybe if I say if (Input.GetAxis("Vertical") != 0)
you can use if( Input.GetButton("Vertical") )
Yes, you can use just that, it works because it is looking for vertical input using (W,D or whatever)