04-26-2024 05:45 AM
Hi all,
I'm coding a VR experiment in Unity using the Meta Quest 3. Everything works so far, but I can't for the life of me figure out why my haptic don't work? Here's a snippet of my code just in case I'm missing something obvious:
using System.Collections;
using UnityEngine;
public class ScreenOverlay : MonoBehaviour
{
public Canvas overlayImage;
public Haptic1 hapticScript; // Reference to the Haptic1 script
private float hapticDuration = 0.5f;
private void Start()
{
// Ensure the overlay image is initially disabled
overlayImage.enabled = false;
// Find and get the CartAppearance script
hapticScript = Object.FindFirstObjectByType<Haptic1>();
}
private void Update()
{
// Detect index button press on the left controller and trigger the flash effect
if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.LTouch))
{
FlashScreen();
StartCoroutine(TriggerHapticFeedback());
}
}
private void FlashScreen()
{
// Enable the overlay image to simulate the flash effect
overlayImage.enabled = true;
// Delay for a short duration (e.g., 0.1 seconds)
StartCoroutine(DisableOverlayAfterDelay(0.1f));
}
private IEnumerator DisableOverlayAfterDelay(float delay)
{
// Wait for the specified delay
yield return new WaitForSeconds(delay);
// Disable the overlay image after the delay
overlayImage.enabled = false;
}
private IEnumerator TriggerHapticFeedback()
{
OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.LTouch);
yield return new WaitForSeconds(hapticDuration);
OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.LTouch);
}
}
I have set up the Meta XR All-in-one SDK in unity and the controller/hand/head tracking is all working fine.