Search Unity

Question MRTK haptics?

Discussion in 'VR' started by xxsmbr, Jan 8, 2022.

  1. xxsmbr

    xxsmbr

    Joined:
    Feb 4, 2021
    Posts:
    51
    Hi all anyone know how I can go about using haptics (quest 2) using MRTK? thanks (using a Quest 2)
     
  2. jozhard

    jozhard

    Joined:
    Dec 15, 2016
    Posts:
    7
    Hi! You need to use the interface IMixedRealityHapticFeedback. This example does a small vibration pulse when you hover an object with a ObjectManipulator script attached to it.

    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.