I have a script which controls player movement and all works fine except for my dash mechanic. When the script first loads the first input of the “Dash” button does nothing but then works perfectly after that, it is as if though the first button press is not being registered. I will add the affected code below. Thank you.
if(direction == 0)
{
if (Input.GetButtonDown("Dodge") && !dodged && (grounded || airDodgeObtained))
{
if(moveX < 0)
{
direction = 1;
}
else if (moveX > 0)
{
direction = 2;
}
}
}
else
{
if(dodgeTime <= 0)
{
direction = 0;
dodgeTime = startDodgeTime;
playerRB.velocity = Vector2.zero;
}
else
{
dodgeTime -= Time.deltaTime;
if (direction == 1)
{
playerRB.velocity = Vector2.left * dodgeSpeed;
dodged = true;
dodgeCooldown = startDodgeCooldown;
if (dodgeJumpUnlocked)
{
canDoubleJump = true;
}
}
else if (direction == 2)
{
playerRB.velocity = Vector2.right * dodgeSpeed;
dodged = true;
dodgeCooldown = startDodgeCooldown;
if (dodgeJumpUnlocked)
{
canDoubleJump = true;
}
}
}
}
if (dodged)
{
dodgeCooldown -= Time.deltaTime;
if(dodgeCooldown <= 0)
{
dodged = false;
}
}