Detect Frecuency/Speed of Pressing a Button

Hi, for a racing game I’m working on, I had the idea of making a game mode in which you have to press as fast as you can a button to make the car go faster and win. But how could I detect the speed in which the player is pressing a button?

Hi, try to save the current time with

``````float startT =time.time;
``````

then count the amout of button presses by increasing an integer for each time the buttion is pressed

``````if (Input.getKeyDown(...)){
count++;
}
``````

then when you want to evaluate the frequency store the current time

``````float endT = time.time;
``````

then subtract the start time from the end time and divide the number of button pushes through the result

``````float frequency = count / (endT-startT);
``````

Regards, BPR

To solve this problem, you don’t need to calculate button frequency. Instead make each button press add just a bit of force/speed So if you are using a Rigidbody, you could do something like:

``````if (Input.GetKeyDown(KeyCode.Space))
``````if (Input.GetKeyDown(KeyCode.Space))