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’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

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:
    969
    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:
    658
    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:
    969
  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:
    658
    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:
    5
    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