Do you want each specific object to have their own custom haptic feedback when interacted in VR?
These codes are here just to do that.
For and in-depth video Justin P Barnett has that covered https://www.youtube.com/watch?v=-5tiV-lyYP8&ab_channel=JustinPBarnett
- Unity project is set up for VR Games.
- Or follow along this tutorial > (https://www.youtube.com/watch?v=yxMzAw2Sg5w&ab_channel=JustinPBarnett) on how to setup.
- Open XR Plugin [Tested on 1.4.2]
- XR Interaction Toolkit [Tested on 2.1.1]
- XR Plugin Management [Tested on 4.2.0]
- Control the haptic feedback's amplitude and duration on any gameobject.
- Add XROrigin to the scene.
- Attach the HapticController.cs script on both the LeftHand Controller and RightHand Controller [XR Origin > Camera Offset > LeftHand Controller & RightHandController].
- Add a SphereCollider on both the LeftHand Controller and RightHand Controller and set the trigger to true.
- Create a Cube in the scene and rename it to HapticCube.
- Add a Rigidbody component to the HapticCube, disable the gravity and enable the isKinematic.
- Create a tag called HapticObject and assign the tag to the HapticCube.
- Add a XR Simple Interactable component to the HapticCube.
- Add the HapticObject.cs script to the HapticCube.
- Adjust the Amplitude and Duration.
- Press Play, put on your headset, reach out towards the HapticCube using your controller and test the feedback.
You can right click on the HapticController component and select Haptic Test when playing. This will give you a sense of how strong do you want the feedback to be. Duration of the haptic feedback is limit to 2 seconds. Let me know if there is a way to increase the duration.
Haptic Controller
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class HapticController : MonoBehaviour
{
public XRBaseController vrController;
[Header("Right Click on this component and select Haptic Test to the feedback strength and duration.")]
[RangeAttribute(0f,1f)]
public float defaultAmplitude = 0.5f;
public float defaultDuration = 0.3f;
private void Start() {
vrController = GetComponent<XRBaseController>();
}
[ContextMenu("Haptic Test")]
public void SendHaptics()
{
vrController.SendHapticImpulse(defaultAmplitude, defaultAmplitude);
}
public void SendHaptics(XRBaseController controller, float amplitude, float duration)
{
controller.SendHapticImpulse(amplitude, duration);
}
private void OnTriggerEnter(Collider other) {
if(other.CompareTag("HapticObject"))
{
other.GetComponent<HapticObject>();
SendHaptics(vrController, other.GetComponent<HapticObject>().amplitude, other.GetComponent<HapticObject>().duration);
}
}
}
Haptic Object
using UnityEngine;
public class HapticObject : MonoBehaviour
{
[RangeAttribute(0f,1f)]
public float amplitude = 0.5f;
public float duration = 0.3f;
}

Attached on both the LeftHand Controller and RightHand Controller.
Variable | Annotation |
VR Controller | Automatically find the XR Base Controller in your GameObject component |
Default Amplitude | Set the default strength of the haptic feedback |
Default Duration | Set the default duration of the haptic feedback |