Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

animator not working with gamepad, but works with Keyboard

Discussion in 'Animation' started by thefalcon38, Jul 28, 2021.

  1. thefalcon38

    thefalcon38

    Joined:
    Mar 11, 2019
    Posts:
    2
    Hey all,
    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.

    Cheers!