I’m messing around with my player movement script and have noticed something which I cannot understand.
The original x-axis movement script (in FixedUpdate) I am using is:
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * moveSpeed, rb.velocity.y);
With this, the player moves around and stops immediately when the button is no longer being pressed down. However, if I move the second line into an “if” statement (shown below), the player slides around like he’s running on ice:
moveInput = Input.GetAxisRaw("Horizontal");
if (moveInput > 0.5 || moveInput < -0.5)
{
rb.velocity = new Vector2(moveInput * moveSpeed, rb.velocity.y);
}
I’m curious why this is happening since both parts of the original script are intact, the only change that I can see is asking the perhaps redundant question of whether or not a button is being pressed down before letting the code run. I am very new to coding so I am expecting the answer to be something very simple, but I can’t find any results on google. Thanks.