Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Feature Request Haptics / Rumble doesn't work with OpenXR?

Discussion in 'VR' started by zezba9000, Apr 16, 2021.

  1. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    1,004
    Does Unity3D not support haptics/rumble with OpenXR yet?

    Using non-OpenXR loaders rumble works fine. Try to use OpenXR and rumble no longer works.
     
  2. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    FlightOfOne and zezba9000 like this.
  3. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Thanks a lot for this!

    I made this class using your script. Hope it helps someone easily call haptic.

    Code (CSharp):
    1.  public class HapticPlayer
    2.     {
    3.         public enum Hand
    4.         {
    5.             Both,
    6.             Left,
    7.             Right
    8.         }
    9.  
    10.         public static void SendHaptic_XRController(Hand hand, float amplitude, float duration)
    11.         {
    12.             switch (hand)
    13.             {
    14.                 case Hand.Both:
    15.                     SendHaptic(XRController.leftHand, amplitude, duration);
    16.                     SendHaptic(XRController.rightHand, amplitude, duration);
    17.                     break;
    18.  
    19.                 case Hand.Left:
    20.                     SendHaptic(XRController.leftHand, amplitude, duration);
    21.                     break;
    22.  
    23.                 case Hand.Right:
    24.                     SendHaptic(XRController.rightHand, amplitude, duration);
    25.                     break;
    26.  
    27.                 default:
    28.                     break;
    29.             }
    30.         }
    31.  
    32.         public static void SendHaptic(InputDevice device, float amplitude, float duration, int channel = 0)
    33.         {
    34.             if (device != null)
    35.             {
    36.                 var command = UnityEngine.InputSystem.XR.Haptics.SendHapticImpulseCommand.Create(channel, amplitude, duration);
    37.                 device.ExecuteCommand(ref command);
    38.             }
    39.         }
    40.     }
    41.  
     
  4. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    1,004
  5. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    The 1.3 release of the OpenXR plugin also has a new Haptic interface that lets you bind the haptic outputs as InputSystem actions and fire the haptics using the action. It will also support frequency as well as amplitude and duration. These new apis will provide better support for controllers with multiple haptics and more control over the haptic feeling.
     
    FlightOfOne likes this.
  6. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    this is great! Any idea when? Also, the above method, will that still be there? I can see cases where you'd need to call them via code.
     
  7. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    No ETA yet
     
  8. ariansyah

    ariansyah

    Joined:
    Dec 9, 2014
    Posts:
    6
    Hello thanks for the code. It works well.

    I am wondering how to achieve continuous rumble only when specific button is being pressed e.g. grip?

    i've tried to change to grip pressed action, but it only triggers once at a time and not continuous.

    thanks in advance

    D