Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
to_the_cosmic_end's avatar
11 months ago
Solved

How to send haptic feedback on UI hover/tap in Jetpack compose?

Hi, I am looking for a way to send small vibration as a haptic feedback on my 2D panel app whenever user hovers their raycast over a UI element, and stronger vibration when they tap on that element. ...
  • dav-s's avatar
    11 months ago

    Hi! You can do this with the SpatialInterface.applyHapticFeedback() function.

    // inside your AppSystemActivity somewhere
    // "spatial" is a SpatialInterface inherited from VrActivity
    // you can pass it around to somewhere else you need it reference it
    spatial.applyHapticFeedback(
       // hand: Apply haptics to the specified controller hand.
       Hand.RIGHT,
       // amplitude: Value between 0 - 1 for strength of haptics.
       0.3f,
       // duration: Time in nanoseconds for how long the haptic feedback should be applied.
       (0.03 * 1e9).toLong(),
       // frequency`: Frequency of vibration (in hz).
       128f
    )

    Hopefully this should help!