Search Unity

[New Input System] Single Tap vs Double Tap

Discussion in 'Input System' started by unity_9R1oHxYOzMhCHw, Jul 2, 2021.

  1. unity_9R1oHxYOzMhCHw

    unity_9R1oHxYOzMhCHw

    Joined:
    Jun 24, 2020
    Posts:
    3
    Hi,

    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 ?

    Thanks,
     
    AlexisGervacio and strongBearCeo like this.
  2. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Need some threshold to wait after one tap to rule out a double tap.
     
  3. unity_9R1oHxYOzMhCHw

    unity_9R1oHxYOzMhCHw

    Joined:
    Jun 24, 2020
    Posts:
    3
    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) ?
     
  4. Seriously? Have you ever seen the UI for tap interactions? Or read the documentation for them?

    screenshot.png
     
  5. MaximilianPs

    MaximilianPs

    Joined:
    Nov 7, 2011
    Posts:
    322
    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.
     
  6. Octopal

    Octopal

    Joined:
    Nov 27, 2016
    Posts:
    8
    1. Get a reference to the InputAction that has the MultiTap interaction.
    2. 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.
     
  7. 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.
     
  8. strongBearCeo

    strongBearCeo

    Joined:
    May 2, 2016
    Posts:
    7
    I faced the same problem. Here's my solution:

    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

    Code (CSharp):
    1. private void ToggleMuteOrDeleteNote(InputAction.CallbackContext obj)
    2.     {
    3.         if (obj.interaction is TapInteraction)
    4.         {
    5.             clipManager.ToggleMuteNotes();
    6.         } else
    7.         {
    8.             clipManager.RemoveMidiNotesInSelectedRegion();
    9.         }
    10.     }
    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.


    strongbear-unity-single-tap-vs-double-tap.png
     
  9. strongBearCeo

    strongBearCeo

    Joined:
    May 2, 2016
    Posts:
    7
    This doesn't always work. If you tap twice but on the second tap, you hold, it also cancel the Multitap but this shouldn't count as a single tap.
     
  10. unity_57FEB384BE82D8C50903

    unity_57FEB384BE82D8C50903

    Joined:
    Aug 4, 2023
    Posts:
    1

    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.