Search Unity

animator not working with gamepad

Discussion in 'Animation' started by Simba254, Sep 16, 2021.

  1. Simba254

    Simba254

    Joined:
    Sep 3, 2021
    Posts:
    5
    Kind of stuck with this one.
    I have an animator controller for a 2d Platform. It all woks fine and dandy using the keyboard,
    but when I use a gamepad, The walk animations will not work.
    it works for shoot, but not for the walk. I know Shoot uses trigger and not set bool, but I've tried trigger for walking and makes no difference.
    My player moved from left to right, so I know the mapping of Gamepad is correct, But animations will not trigger.
    Anyone have an Idea of what I'm missing or doing wrong. Please see below the code for the move function of the player.

    void Update()
    {
    if (shootCounter > 0) shootCounter -= Time.deltaTime;

    float move = Input.GetAxisRaw("Horizontal") * speed * Time.deltaTime;

    jump(move); // jump function of player
    shootTimer(); // shoot function of player

    if (move < 0)
    {
    if (!isjumping)
    {
    animator.SetBool("walk left",true);
    animator.SetBool("walk right", false);
    animator.SetBool("idle", false);
    direction = 0;
    }

    } // move left

    if (move > 0)
    {
    if (!isjumping)
    {
    animator.SetBool("walk right", true);
    animator.SetBool("walk left", false);
    animator.SetBool("idle", false);
    direction = 1;

    }

    } // move right

    transform.Translate(move, 0, 0);

    if (!(Input.anyKey))
    {
    if (!isjumping)
    {
    animator.SetBool("walk right", false);
    animator.SetBool("walk left", false);
    animator.SetBool("idle", true);
    }
    }
    }

    any help would be appreciated.