I’m working on a android app made with Unity and I’m using the new input system.
I try to make different actions on ‘single tap’ and ‘double tap’ but when the user double-tab, it also trigger two times the simple tap.
Is there any solution to differentiate simple and double tap ?
Thank you for your answer.
Is there any way to do this with the Input System or I have to code it by myself (by firing an event after 0.4 s for example) ?
Ok but how to recognize if the user want to move backward or double-tap to roll back?
What is happen during the test with the S button is that, the character first turn on the camera side, and the roll back.
So I need to filter in some way the button push, maybe I could wait for 6ms to check what is going on.
Get a reference to the InputAction that has the MultiTap interaction.
Use the started and performed callbacks on the action, with your own threshold, to determine whether it was a single or multi tap. The started callback is called when the first tap is performed, and performed is called when the multi tap is performed.
If you do this and you need either or and not and, you need the cancel too. Set up a multitap, set the callback to performed and canceled. performed → multitap canceled → single tap if the multitap tap count is 2.
I setup an combined action with 2 interactions: MultiTap and Tap. The multitap interaction is placed above the tap interaction.
Then in the Performed callback, I check for the interaction, like this
private void ToggleMuteOrDeleteNote(InputAction.CallbackContext obj)
{
if (obj.interaction is TapInteraction)
{
clipManager.ToggleMuteNotes();
} else
{
clipManager.RemoveMidiNotesInSelectedRegion();
}
}
A draw back with this solution is that it’ll take a while to trigger the Tap interaction because it has to wait for the Multitap interaction to be cancelled.
Indeed @strongBearCeo regarding the draw back, which in my case is somewhat of a deal breaker because i want a tap and a single tap to perform a character move, the delay makes the game feel “laggy”.
Its amazaing that Unity couldn’t figure this out and provide a proper API to handle Tap and DoubleTap, computers has this feature for the last ~40 years or so with mouse click vs dblClick.
In case this helps anyone, because the official docs are outdated, heres the actual tooltips found on the scripts (that wont show in editor as of input 1.11.2):
Max Tap Spacing: The maximum delay in seconds allowed between each tap. If this time is exceeded, the multi-tap is canceled.
Max tap duration: Time in seconds within with a control has to be released again for it to register as a tap. If the control is held for longer than this time, the tap is canceled."
Press Point: The amount of actuation a control requires before being considered pressed.
Having it in the same Action does create a lag, as it waits for the multitap to cancel. I created two separate Actions for Walk (Tap) and Run (Multitap). This works for my scenario where the player can start walking while waiting for the second tap.