Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question How do I use interactions properly? -- Performed seems to be true every time button is pressed

Discussion in 'Input System' started by trevor520, Jul 20, 2020.

  1. trevor520

    trevor520

    Joined:
    May 17, 2020
    Posts:
    5
    I am trying to do very basic functionality where when the space bar is tapped the player does a single jump and when pressed the player does a double jump. I have tried multiple different way without getting desired functionality.

    The closet I came was using something like..
    Code (CSharp):
    1.  
    2.     public void OnJump(InputAction.CallbackContext context)
    3.     {        
    4.      
    5.         if (context.interaction is TapInteraction && _currState == IdleState)
    6.         {
    7.             JumnpState.doubleJump = false;      
    8.             TransitionToState(JumpState);
    9.         }
    10.         if (context.interaction is PressInteraction && _currState == IdleState)
    11.         {
    12.             JumnpState.doubleJump = true;
    13.             TransitionToState(JumpState);
    14.         }
    15.  
    16.     }
    17.  
    however despite the Press being set to press only in the Input Actions it only triggers once I release the space bar.

    The documentation is written such that it sounds like performed evaluates to True when the interaction on that action is completed however. The behaviour I get is performed evaluates to true when the button is pressed. i.e. seems to be having the same was as
    Code (CSharp):
    1. context.started
    I'm not sure where I am going wrong. Set-up in my awake method is as follows

    Code (CSharp):
    1.         playerInput = new PlayerInput();
    2.         playerInput.PlayerControls.SetCallbacks(this);  
    where PlayerInput is the name of the Action Input.
    Unity Version is 2019.3 and Input System Version 1.0
     
  2. tanayg

    tanayg

    Joined:
    Jul 20, 2020
    Posts:
    5
    I believe you will need to have two different actions for the space key in your Input Actions Asset. For Double Jump, you will need to add a Hold interaction, where you can specify the hold time to trigger the action.

    For your reference:
    upload_2020-7-21_9-19-14.png
     
  3. trevor520

    trevor520

    Joined:
    May 17, 2020
    Posts:
    5
    Thanks, I will try this today with the Hold interaction. I did try two different actions yesterday one with press and one with tap but again even though press was "Press Only" double jump would be triggered on release
     
  4. FullMe7alJacke7

    FullMe7alJacke7

    Joined:
    Dec 17, 2013
    Posts:
    55
    I just was looking over a comment on youtube from 2 months ago and as of then, there was issues still with binding more than 1 action to the same button.

    Example, if you have an action triggered by "B" and another one triggered by "Shift + B" when you hit shift the standard "B" button action is still triggered. This could be part of the problem as it seems like there's no definitive list of features that are just "there" and don't actually work yet.

    On a side note, I went about handling my input slightly differently.

    Code (CSharp):
    1.         public void Initialize()
    2.         {
    3.             if (_inputMap == null)
    4.                 _inputMap = new InputMap();
    5.  
    6.             _inputMap.Player.Move.Enable();
    7.             _inputMap.Player.ShiftModifier.Enable();
    8.             _inputMap.Player.ShiftModifier.performed += ctx => ShiftModifier = true;
    9.             _inputMap.Player.ShiftModifier.canceled += ctx => ShiftModifier = false;
    10.             _inputMap.Player.Move.performed += ctx => RawInput = ctx.ReadValue<Vector2>().normalized * movementSensitivity;
    11.             _inputMap.Player.Move.canceled += ctx => RawInput = Vector2.zero;
    12.         }
     
    trevor520 likes this.
  5. trevor520

    trevor520

    Joined:
    May 17, 2020
    Posts:
    5

    I was able to get the it to function the way I wanted using hold, so that's nice. Was also thinking of giving something like this a shot i.e. customization that I want in script
     
    FullMe7alJacke7 likes this.