#Unity animator troubleshooting

1 messages · Page 1 of 1 (latest)

mellow torrent
#

Hi 😊
I'm trying to animate a pinball paddle depending on the user's input using Unity's Animator component.
Expected behavior:
Hold down the "A" key to cause the paddle to go up.
Release the "A" key to cause the paddle to go down.
Current result:
The paddle works as expected however, if you hold down the "A" key until the paddle is at the end of it's animation and release, the paddle will instantly return to its resting position.

Here is also a snippet of the code that is effecting the animator.

public class PaddleController : MonoBehaviour
{
    Animator anim;
    
    void Start() {
        anim = GetComponent<Animator>();
    }
    
    void Update() {
        if (Input.GetKey(KeyCode.A)) {
            anim.Play("ActivatePaddle");
            anim.SetFloat("direction", 1);
            anim.SetBool("isResting", false);
        } else {
            anim.SetFloat("direction", -1);
            anim.SetBool("isResting", true);
        }
    }

}
#

Condition for the transition ActivatePaddle -> Rest

#

How do I prevent the paddle from instantly returning to its resting position when the user lets go of the "A" key?

cedar cedar
#

Not that familiar with Unity yet, but you might have to think about it differently than on simple Bool basis

For example, have it set up in a way that player holding A will gradually raise some float from 0-100.. and have it automatically lower itself if A isnt being held.

Therefore if you stop holding at 56% of way, it will start going down from those 56%. Once you pair your animation to that percentage it should not be snapping to starting position but slowly go back from those 56% back down to 0% of animation

#

I'm not saying it's the right way, and you might have to look up some things ... or ask smarter people around here..