I’m trying to make a script to control my animations. I made a transition with a bool parameter to go from walking animation to idle animation. I want the bool to be true when the player is moving so that the player doesn’t idle and false when the player isn’t moving so that the player does idle. For some reason, when I move my character backwards, the bool is true and the walking animation plays fine. But when I move my character forward, the bool does not become true and the animations get stuck in this back and forth between walking an idle. I’m really confused because there doesn’t seem to be anything wrong. BTW, I’m extremely new to coding and unity.
Here is the script
public class Animations : MonoBehaviour
{
private Animator anim;
private float vert;
// Start is called before the first frame update
void Start()
{
anim = GetComponent();
}
// Update is called once per frame
void Update()
{
if (anim.GetFloat("Walk") == 1)
{
anim.SetBool("Idle", true);
}
else
{
anim.SetBool("Idle", false);
}
if (anim.GetFloat("Walk") == -1)
{
anim.SetBool("Idle", true);
}
else
{
anim.SetBool("Idle", false);
}
vert = Input.GetAxisRaw("Vertical");
anim.SetFloat("Walk", vert);
}
}