Search Unity

Using Tap and Hold for different actions with a single Trigger?

Discussion in 'Input System' started by StrangeVoyager, Jan 22, 2020.

  1. StrangeVoyager

    StrangeVoyager

    Joined:
    Oct 13, 2013
    Posts:
    4
    I'm using an Xbox One controller, and am experiencing some unexpected behavior.

    I have successfully set the right shoulder button to fire a single shot with a quick tap, and a multi-shot with a hold. I added a Tap interaction, followed by a Hold interaction, in the "Throwing Star" Action. In the Performed callback, if the interaction is a hold, it does the multi-shot. Otherwise, a single shot is fired. This is working as expected.

    I'm attempting to replicate this setup with the right trigger and melee combat. A quick press and release should result in a light melee attack. Holding the trigger should result in a heavy melee attack. Using the same Action setup and code, it works except that after a hold and successful heavy melee attack, the light melee attack is sometimes performed when the trigger is physically released. There is no consistency as to when/whether this happens. Is this a bug in the Input system, or is this a hardware issue where there's enough bounceback that the Input system thinks there's been another quick press of the trigger?

    Here is the code:

    Code (CSharp):
    1. controls.Player.MeleeAttack.performed +=
    2.     ctx =>
    3.     {
    4.         if (ctx.interaction is HoldInteraction)
    5.         {
    6.             MeleeAttack(true); // Heavy attack        
    7.         }      
    8.  
    9.         else
    10.         {
    11.             MeleeAttack(false); // Light attack
    12.         }        
    13.     };
    Edit: I did some further debugging, and made a public bool that's true when the value of the Melee Attack is not equal to 0. This is only set to true right in the middle of the trigger being down. I tried it both as a button and a value (using Analog and Axis Control Types). I moved melee to the left shoulder button and it works as expected. For future reference, is there a way to work with the trigger to accomplish my goal, or am I better off just using the triggers for single actions?

    Thanks so much for any help!
     

    Attached Files:

    Last edited: Jan 22, 2020