I have a function that disables the movement of the player for the duration of an animation.
IEnumerator AnimationRooting(float seconds) //Locks player in a root state after attacking
{
pStats.canMove = false;
rigidbd.velocity = new Vector2(0, 0); //Sets the player in a root state
yield return new WaitForSeconds(seconds);
Input.ResetInputAxes(); //Disables the player from instantly accelerating to a 100%
pStats.canMove = true;
}
If I comment Input.ResetInputAxes the players stops temporarily before he accelerates at the same speed as before. (Assuming the person has held down the Input keys the whole time)
When I have that line of code the acceleration is smooth, however, I found a bug.
Assuming I’ve held down both down and right arrow - the player moves diagonally until I press the attack button and the function is called. The player is still for x seconds and then accelerates in only one axis. The other one is completely locked until I let go of the button and press it down again.
Here is a representation of what I mean:
If you can’t open it comment on my question and I will try to link it to you.
Here is my movement code in case you want to test it yourself:
private void FixedUpdate()
{
if (pStats.canMove == true)
{
Vector2 movePos = Vector2.right * Input.GetAxis("Horizontal") + Vector2.up * Input.GetAxis("Vertical");
rigidbd.velocity = movePos * Time.deltaTime * 50 * moveSpeed;
}
}