Movement Sticking
I've been working on a character controller and have encountered a problem that is a bit annoying while playing. When moving horizontally I am able to tap up or down and the character will move accordingly for the duration of my tap and then return to the horizontal direction so long as that key remained held down. This is the desired effect. However, when moving vertically, and the opposite is attempted by tapping left or right the character remains moving up or down. The character seems to stick and will not move horizontally until vertical movement stops. How might I go about fixing this?
My code can be seen here.
float input_x = Input.GetAxisRaw("Horizontal"); // get input.
float input_y = Input.GetAxisRaw("Vertical"); // get input.
// REMOVE DIAGONAL
if (Mathf.Abs(input_x) > Mathf.Abs(input_y))
{
input_y = 0f;
}
else
{
input_x = 0f;
}
// END
bool isWalking = (Mathf.Abs(input_x) + Mathf.Abs(input_y)) > 0; // figure out if we are moving.
sprAnimator.SetBool("isWalking", isWalking); // set the animator's bool based on what we find.
if (isWalking == true) // check if we are moving or not.
{
sprAnimator.SetFloat("x", input_x); // update the animator's blend parameter.
sprAnimator.SetFloat("y", input_y); // update the animator's blend parameter.
transform.position += new Vector3(input_x, input_y, 0).normalized * moveSpeed * Time.deltaTime; // move us.
}
Comment