Search Unity

Question Wait until stick has been released?

Discussion in 'Input System' started by steinbitglis, Jun 1, 2021.

  1. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    254
    Hi!
    I'm trying to create an interactive remapping sequence. I'm using RebindOperation and its OnApplyBinding.
    But I need a way to wait for an analog stick to return to a neutral position before moving on to the next
    mappable InputAction. Otherwise, as soon as any analog stick is actuated, it will map to all the remaining InputActions in my sequence, as they all start and map immediately (the stick is still actuated). This does not happen for buttons.

    The code goes something like this.

    Code (CSharp):
    1.    
    2.         foreach (var op in ops) {
    3.             selectedControl = null;
    4.             rebind = GetBindingOp();
    5.  
    6.             while (rebind != null)
    7.                 yield return null;
    8.         }
    9.  
    10.         RebindingOperation GetBindingOp() {
    11.             return new RebindingOperation()
    12.                 .OnMatchWaitForAnother(0.05f)
    13.                 .WithControlsExcluding("<Pointer>/delta")
    14.                 .WithControlsExcluding("<Pointer>/position")
    15.                 .WithControlsExcluding("<Touchscreen>/touch*/position")
    16.                 .WithControlsExcluding("<Touchscreen>/touch*/delta")
    17.                 .WithControlsExcluding("<Mouse>/clickCount")
    18.                 .WithMatchingEventsBeingSuppressed()
    19.                 .OnCancel      ( BindCancel )
    20.                 .OnComplete    ( BindComplete )
    21.                 .OnApplyBinding( BindApply )
    22.                 .Start();
    23.         }
    24.  
    25.         void BindCancel (RebindingOperation operation) {
    26.             rebind?.Dispose();
    27.             rebind = null;
    28.         }
    29.        
    30.         void BindComplete (RebindingOperation operation) {
    31.             rebind?.Dispose();
    32.             rebind = null;
    33.         }
    34.  
    35.         void BindApply (RebindingOperation operation, string path) {
    36.             selectedControl = operation.selectedControl;
    37.             pathsReturned[pathIndex++] = path;
    38.         }
    39.  
     
    Last edited: Jun 1, 2021
  2. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    254
    I'm getting a lot of different events during the mapping process. Is there a proper way to isolate and lock on to one of them.
    My left stick will result in a "Stick:/joystick/x" (axis controller) or "Stick:/joystick" (stick control), depending on which axis i move the stick. At the same time I also 4 different ButtonControls. On the right stick I only get "rz" and "z", which are axis controllers, and no button controls.
    What I'm trying to achieve is that the user can move a stick or press a button, so that I can identify it and associate a hint with that input later. I'm struggling because I don't know if they're going to be sending an axis, button or stick, or a combination of those.

    The user will see something like this:
    press_button.png
     
  3. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    254
    I just found that when reading from newly mapped controls, I have to wait for a while (0.05 seconds) before any input will be returned from AxisController.ReadValue(), even if the very same input just caused the mapping to happen in the first place. So for a while 0 will be returned, then I will get the real data, and only then, can I start waiting for the input axis to return to a resting position.
     
  4. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    254
    For buttons, if mapping with
    .WithMatchingEventsBeingSuppressed()
    , there is no way to get the button value from the control, so I can not wait until the button has been released. The control API will be dysfunctional until the button has been released.
     
  5. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    254
    I've chosen to pretend
    .WithMatchingEventsBeingSuppressed()
    doesn't exist, and deal with the consequences.

    The reasoning goes like this:
    1. We can not continue the remapping process after an axis has been actuated, before the same axis has returned to its resting position.
    2. So the UI will proceed to map the next input only when the users fingers are back in resting position.
    3. And since the user is doing an eye-hand kind of coordination, we should not treat buttons differently from the axes, since they are required in succession.
    4. So we will be waiting for the buttons also to return to their resting position.
    5. So we need
      ButtonControl.isPressed
      to return real values.
    6. So we can not use
      .WithMatchingEventsBeingSuppressed()
      when mapping.