Jump to content

Check if key has been double tapped?


Piggy
 Share

Recommended Posts

Hi,

I'm trying to make my character charge forward if the player double taps on any of the control keys, but I can't figure out how to do it. Is there any built in functionality for this that I'm missing? I could settle for checking if the player quickly taps the key, and I tried to use a combination of key.onUp and key.duration to see if the keys was pressed for a very short time, but this doesn't really seem to be very precise (or I'm doing it wrong :) ).

Would be grateful for any help or any suggestions!

Link to comment
Share on other sites

There is no such functionality, so you have to write your own script for that.

You could do 2 things:

 

1. Always have a short delay on keyup.

e.g.

 

keyup

-> check if timer active,

if yes -> cancel timer and emit charge forward,

if no -> timer = setTimeout(normaltap, 100); <- or whatever delay

 

2. check last tap time

 

keyup

-> check if difference between time and last time you pressed the key is less than 100 ms (or whatever delay you prefer)

if yes, set the time to 0 and emit charge forward (0 so that the next keyup wont trigger another double tap if you mash the key too fast)

if no, emit normaltap and save the current time for this key

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...