- Home /
How to detect Input.GetAxis double tap?
I'm working on a beat em up and would like the player to run when Input.GetAxis("Horizontal") is double tapped, however there doesn't seem to be a built in way to detect that. There also doesn't seem to be a way to detect if a dpad was pressed, only held.
Is it possible, or is there another way to simulate this?
Answer by Chimz · Sep 25, 2021 at 07:51 PM
Maybe there is a better way than what I'm about to suggest (I'm not an expert programmer) but you can simulate it yourself.
Let's say we wanna double tap A for a special hit, Try using a Float Timer to start counting after the player hits A once We'll set a small time limit like 0.2 seconds (experiment with the number to avoid too much input lag)
So Player hits A, the counter starts if the timer reaches the Limit and A has not been pressed a second time, do the default A button attack. But if A is pressed again in the window limit, then do the Double-Tap attack instead
You could maybe use this as a Method to save yourself from writing it over and over for each button Hope this helps
Unfortunately there seems to be no way to read GetAxis as a button (bool), only a float. I ended up creating a separate run button as a workaround.
You mentioned that it's a button. A button can be used both in Input.GetAxis and Input.GetButton. You can use the Input.GetButtonDown for this.
Answer by Gokushivum · Sep 27, 2021 at 04:27 AM
I'm also not an expert, but building off of Chimz's answer, you mentioned that you are reading the axis as a float, so what you could do is check if the GetAxis is greater than some threshold (1 isn't probably the best, so something like +- .7 may be good for some leniency) check if it is less than the threshold and within the timer and again if it is over the threshold, basically have 3 states that simulate each part. There is probably a different better way but that is one way off the top of my head