How to code a Double Tap Axis Recognition?

Hello coding peoples,

I was wondering if by any chance you guys knew how to code up recognition of double tapping of a button or axis?
I’m specifically looking for Axis recognition but I will probably also be using this logic for buttons in the future.

Specifically this is what I’m trying to do

My character runs in any 8 directions. I want to be able to double tap in a direction and my character takes off sprinting. I already have the sprinting prototyped and now I’m trying to set it to the proper input. (right now it works off a button press that I created for testing the movement to my satisfaction.)

I’d want to avoid double tapping in opposite directions to turn on sprint and also avoid when you’re already running (not sprinting) and you stop quickly and run again from turning on the sprint. it should only specifically turn on when you’ve double tapped it.

Even if you guys can’t help me with code, pseduo code would be much appreciated. I’m just trying to wrap my mind around some kind of logic to attempt this.

Thank you,
Alex Batista

Off the top of my head, you want a means of tracking the last input (both axes) and how long ago it was, and how long it was held. So that initial input will start a couple of counters (delta to next input, input hold time) (maybe use delta time or a tick counter). Then on the next input, you’ll want to record both axes on input and then figure out a reasonable tolerance check for the next input, to ensure it’s pretty close to being in the same direction twice. Obviously you’ll want a means to check and reset those counters so you know when it’s appropriate to listen for a second input.

I’m not sure if you want to filter other input types (you may want to hold down the trigger to fire and sprint for example).

For axis input, I think DanaFo’s answer is generally the way to go. For button presses, you might consider using the handy “IE_DoubleClick” event. I currently use it for sprinting to good effect.

Thank you for this :smiley: this already gives me a great idea of how to implement this!!

Thank you!! :smiley:

This is good to know, I’ll see if I can mock something up because I know we’re going to have something for a double tap on button event. Thank you.