- Home /
2D character sliding after velocity become 0
I am new to unity and I am trying to work on a 2d character controller. But I found that my character usually slides after I let go my keyboard button. How can I fix it?
void FixedUpdate()
{
move = Input.GetAxis("Horizontal");
if (move == 0)
{
Debug.Log("N");
rb.velocity = new Vector2(0, rb.velocity.y);
} else
{
Debug.Log(move);
rb.AddForce(new Vector2(move * movingspeed, 0));
}
}
Answer by Namey5 · Mar 21, 2020 at 01:36 AM
By default, when you use keyboard input as an axis, the Input system applies some filtering to make it feel more like an analogue axis rather than a digital one. That means that even though you may have let go of the key, the Input system will filter it towards the current value over time. If you wish to make this more snappy, you can either increase the sensitivity and gravity of the input in the Input settings window, or you can use the GetAxisRaw method (which removes all input filtering);
https://docs.unity3d.com/ScriptReference/Input.GetAxisRaw.html
Your answer
Follow this Question
Related Questions
2dToolkit and Physics2D.OverlapCircle 2 Answers
Inconsistent 2D collision detection since 5.2.3 1 Answer
Deactivate Key. 2 Answers
How do i make a player or move around any side of a platform 2 Answers