Character keeps moving a moment after I release input keys

I’ve searched but not found my exact problem so here it is:

Top down 2D game with a sprite character moving forward/backward/strafing with WASD/arrow keys. He looks at mouse. I move him with the following code (in Update). Using Unity 5.

		transform.Translate ((transform.up*Input.GetAxis("Vertical") + transform.right*Input.GetAxis("Horizontal")).normalized *speed*Time.deltaTime);

The code works to move the character but the problem is the character keeps moving for about a half second after the input keys are released. This gives the controls a very unresponsive feel and the character seems as if he’s slipping across the floor.

If I only tap the key, the effect isn’t so bad, but if I hold it at all I get the problem. I should mention that if I hold the key for 1 second or for 60, he’ll stop moving after the same amount of time (about a half second). It doesn’t get worse the longer I hold, is what I mean to say.

Is there a better way to move the character? Put code in FixedUpdate but had the same problem.

Thanks for any help provided.

That’s because Input.GetAxis() returns a smoothed output.

Try using Input.GetAxisRaw(). Eg:

transform.Translate ((transform.up*Input.GetAxisRaw("Vertical") + transform.right*Input.GetAxisRaw("Horizontal")).normalized *speed*Time.deltaTime);

Hope that helps!

S_Darkwell’s answer is right on, but there is also another solution besides Input.GetAxisRaw()

Although Input.GetAxis() returns a smoothed output that reaches 1 and -1 somewhat slowly and returns to 0 somewhat slowly, this can be sped up in the Edit/Project Settings/Input menu.

If you look at your axis, in the InputManager, there are options for Gravity and Sensitivity.
Sensitivity is how fast the output reaches 1 or -1
Gravity is how fast the output returns to 0

If you raise these values, you can have smoothed GetAxis() input that is much more responsive.

I believe it worked better in FixedUpdate for me in the end, though this is an old project for me now…