- Home /
Double tap to dash (With Multiple keypress)
Hi i am trying to implement a keyboard double tap features to dash my character. I encounter a problem of detecting diagonal key press which involve 2 key press. Example (up and Left key) within a frame. so that will detect diagonal. Problem is i am having trouble trying to detect 2 keypresses within 1 frame. I tried implementing a buffer to detect the next keypress before double tap but it has a very low success rate.
> if(Horizontal != 0)
>{
> bufferTime = Time.time;
> bufferOn = true;
> bufferCount = 1;
> lastTapTime = Time.time;
> keyInput |= (Horizontal < 0) ? keyDirection.Left : keyDirection.Right;
> }
>else if(Vertical !=0)
>{
> bufferTime = Time.time;
> bufferOn = true;
> bufferCount =2;
> lastTapTime = Time.time;
> keyInput |= (Vertical < 0) ? keyDirection.Bottom : keyDirection.Top;
> }
> if (bufferOn == true)
> {
> if(Vertical != 0 && bufferCount == 1)
> {
> keyInput |= (Vertical < 0) ? keyDirection.Bottom : keyDirection.Top;
> lastTapTime = Time.time;
> keyPressed = true;
> bufferCount = 0;
> }
> else if (Horizontal != 0 && bufferCount == 2)
> {
> keyInput |= (Horizontal < 0) ? keyDirection.Left : keyDirection.Right;
> lastTapTime = Time.time;
> keyPressed = true;
> bufferCount = 0;
> }
> else
> {
> bufferCount = 0;
> keyPressed = true;
> lastTapTime = Time.time;
> }
>}
Btw i don't need the user to keep holding on the buttons because i just want user to double tap and let the code (or player object) do the rest of the dash. So it's only tap, not hold.
Your answer
Follow this Question
Related Questions
Playing Animation When Two Keys Are Held Down To Play Run Animations 0 Answers
Barrel Roll on Double Key Press, right & left 2 Answers
Multiple Object Collider Detection to load new scene 1 Answer
Detect touches on the top right corner of the screen 1 Answer
How to detect sprite in player's position (2D Platformer Game) And get it t do something 2 Answers