Character Dashing Movement

Hi, I would like to ask on how to code on the movement of character. Basically, when I press my right arrow key, it will move right, and when I press my left shift, it will dash for a certain time(using int dashcounter) The problem comes in, players could constantly spam SHIFT to allow the character to infinetly dash, how do i control/prevent it?

if (CP_Input_KeyDown(KEY_RIGHT) )
    {
        movementH = right;
        if (CP_Input_KeyDown(KEY_LEFT_SHIFT) && dashcounter < 20)
        {
           
            movementV = CP_Vector_Zero();
            movementH = CP_Vector_Add(right, dash);
            dashcounter += 1;

        }
    }
    if (CP_Input_KeyReleased(KEY_LEFT_SHIFT))
    {
        dashcounter = 0;

    }

You can set a boolean variable to true when the key is pressed

Reset it to false on key release

now check the variable when the key is pressed and
don’t act when it’s true already

1 Like

Thanks for the advice! It elightens me on how to solve it, thank you!

1 Like