Search Unity

Walk animation not leaving "walking" state

Discussion in '2D' started by maddaddam12, Mar 1, 2019.

  1. maddaddam12

    maddaddam12

    Joined:
    Feb 19, 2019
    Posts:
    7
    Hey all, I have an animation that will transition from idle to moving but when i stop pressing the button the animator is still showing the "move" state to be active and the animation loops over and over, sorry if this is real simple like but I'm at my wits end, thanks for any help!

    some relevant images from the animator and the code
    https://imgur.com/a/whB0uzn
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    It looks like your Move parameter in the Animator is a trigger instead of a bool. Try changing it to a bool instead so it can just be a true or false state activation. If you have to keep it as a trigger for some reason, try manually turning the trigger off with code when the keys are not pressed.
     
    maddaddam12 likes this.
  3. maddaddam12

    maddaddam12

    Joined:
    Feb 19, 2019
    Posts:
    7
    Thanks for the reply! didn't seem to work though and it looks like it is a boolean after all, trigger has a different tick-box shape

    https://imgur.com/a/NJoCIYz
     
  4. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    I knew they were different but couldnt remember which was which lol. Sorry about that. 2 other ideas then, have you tried using GetKeyDown instead of GetKey? If that doesn't work, in your code it says anim.SetTrigger, maybe it needs to be anim.SetBool? Just shooting ideas out there since I am not on my home computer.
     
    maddaddam12 likes this.
  5. ManiaCCC

    ManiaCCC

    Joined:
    Aug 15, 2015
    Posts:
    41
    But again, it's weird - you are using bool in animator and you call trigger in code? How this can work?
     
    maddaddam12 likes this.
  6. maddaddam12

    maddaddam12

    Joined:
    Feb 19, 2019
    Posts:
    7
    Oh gosh I didn't even see the SetTrigger thing in the code (I didn't do the code on this bit)
    When I try and switch to anim.SetBool it throws the below error, but I think I'll go ad take that to our coder. Thank you so much!

    Assets\Code\CharacterAnimator.cs(18,12): error CS1501: No overload for method 'SetBool' takes 1 arguments
     
  7. ManiaCCC

    ManiaCCC

    Joined:
    Aug 15, 2015
    Posts:
    41
    you need send state into it like SetBool("Move", false)
     
    Cornysam likes this.