How Can I Fight Button Mashing - Need To Slow Down Input Rate

Hi everyone,

I’ve got a platform fighting game that I’ve been doing this week as a sort of mini-jam, and I was wondering how I could delay inputs from the “punch” button. I have a basic trigger on my player that collides with the other player’s trigger. When P1 uses GetKeyDown(KeyCode.X) while OnTriggerStay is happening, it causes -5 damage to the other player.

Often it registers twice (so -10 on one punch) and I suspect it’s because I’ve made my timestep very small to help read collisions, thus registering two hits in the small time the player activates the key.

I want to set the punch keys to only register every .1 seconds, or something a bit quicker, so you can’t just pound the key and do -50 damage in one second.

Any help would be appreciated!

Pat,Hi everyone,

I’ve got a platform fighting game that I’ve been doing this week as a sort of mini-jam, and I was wondering how I could delay inputs from the “punch” button. I have a basic trigger on my player that collides with the other player’s trigger. When P1 uses GetKeyDown(KeyCode.X) while OnTriggerStay is happening, it causes -5 damage to the other player.

Often it registers twice (so -10 on one punch) and I suspect it’s because I’ve made my timestep very small to help read collisions, thus registering two hits in the small time the player activates the key.

I want to set the punch keys to only register every .1 seconds, or something a bit quicker, so you can’t just pound the key and do -50 damage in one second.

Any help would be appreciated!

Hi, Instead of checking for GetKeyDown in your Update function check it in another function that gets executed every .1 seconds by using InvokeRepeating:

in your controller script:

function Update(){
 if(playerIsControllable && !IsInvoking("CheckInputs")){ // if we are not already checking for inputs and the player is controllable (boolean that is true during the fight) we start checking for inputs every .1 seconds
      InvokeRepeating("CheckInputs",0,0.1); //starts imediately to execute CheckInputs() every 0.1 seconds
     }
 if(!playerIsControllable){ // if the player is not controllable (eg during startup) we stop checking for inputs.
  CancelInvoke("CheckInputs");
 }
}

function CheckInputs(){
 //put all your getKeydown stuff in here.
}

Let me know if you have any problems with that concept.