Search Unity

Microsoft Mixed Reality Controller Haptics

Discussion in 'AR/VR (XR) Discussion' started by spinaljack, Oct 17, 2017.

  1. spinaljack

    spinaljack

    Joined:
    Mar 18, 2010
    Posts:
    992
    Hi,

    Anyone got an example of how to make the hand controller rumble?

    Thanks
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
  3. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
  4. spinaljack

    spinaljack

    Joined:
    Mar 18, 2010
    Posts:
    992
    Can you not just link to the relevant documentation page for motion controller haptics? I've been googling all day. I've got position and button data sorted, just need the rumble feature working.

    Thanks
     
    arufolo likes this.
  5. decktwelve

    decktwelve

    Joined:
    Feb 1, 2016
    Posts:
    2
    For those still searching, the Mixed Reality Toolkit has an API for rumble (link). Note that as of this writing there is an open issue that causes rumble to *NOT* work in the Unity Editor (it crashes for me), but it works fine when deployed. Here's a super-simple code sample.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.XR.WSA.Input;
    3. using HoloToolkit.Unity;
    4.  
    5. public class InputRumble : MonoBehaviour
    6. {
    7.     private void OnEnable()
    8.     {
    9.         InteractionManager.InteractionSourcePressed += InteractionManager_InteractionSourcePressed;
    10.     }
    11.  
    12.     private void OnDisable()
    13.     {
    14.         InteractionManager.InteractionSourcePressed -= InteractionManager_InteractionSourcePressed;
    15.     }
    16.  
    17.     private void InteractionManager_InteractionSourceReleased(InteractionSourceReleasedEventArgs obj)
    18.     {
    19.         // Subtle rumble on release
    20. #if !UNITY_EDITOR
    21.         obj.state.source.StartHaptics(0.25f, 0.25f);
    22. #endif
    23.     }
    24.  
    25.     private void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs obj)
    26.     {
    27.         // Intense rumble on press
    28. #if !UNITY_EDITOR
    29.         obj.state.source.StartHaptics(1.0f, 1.0f);
    30. #endif
    31.     }
    32. }
    33.  
     
    theYoekkul and spinaljack like this.
  6. arufolo

    arufolo

    Joined:
    Mar 5, 2013
    Posts:
    8
  7. Relspace

    Relspace

    Joined:
    Jun 7, 2018
    Posts:
    7
    MadeFromPolygons likes this.
  8. dvr7

    dvr7

    Joined:
    Apr 24, 2016
    Posts:
    34
    2018.3 release notes has this

    Haptics APIs for VR controllers

    We now provide APIs for triggering haptics on the Windows Mixed Reality headset controller, Vive controller through OpenVR, and Oculus Touch controllers. We’ll continue expanding platform support and creating more feature abstractions in future releases.
     
  9. jozhard

    jozhard

    Joined:
    Dec 15, 2016
    Posts:
    7
    For anyone that finds this thread after browsing for a while without luck (like me), here is a working example of making a vibration pulse when hovering over an object with an ObjectManipulator attached.


    Code (CSharp):
    1. using UnityEngine;
    2. using Microsoft.MixedReality.Toolkit.UI;
    3. using Microsoft.MixedReality.Toolkit.Input;
    4.  
    5. public class Vibration : MonoBehaviour
    6. {
    7.     ObjectManipulator _manipulator;
    8.  
    9.     private void Awake()
    10.     {
    11.         _manipulator = GetComponent<ObjectManipulator>();
    12.         _manipulator.OnHoverEntered.AddListener(OnHoverEnter);
    13.     }
    14.  
    15.     private void OnHoverEnter(ManipulationEventData data)
    16.     {
    17.         var hapticController = data?.Pointer?.Controller as IMixedRealityHapticFeedback;
    18.         hapticController?.StartHapticImpulse(0.4f, 0.5f);
    19.     }
    20. }
    21.