Skip to content

r3f-xr-widgets / vibrateOnEvent

Function: vibrateOnEvent()

vibrateOnEvent(e, pulse?): void

Defined in: src/utils/vibrateOnEvent.ts:47

Trigger haptic feedback on XR controllers when an event occurs.

Uses the WebXR Gamepad API's hapticActuators[0].pulse() method to provide tactile feedback to users in VR/AR. Only triggers if the event comes from an XR controller input source.

Parameters

e

any

Pointer event from React Three Fiber interaction

pulse?

PulseConfig

Optional pulse configuration (intensity and duration)

Returns

void

Example

tsx
import { vibrateOnEvent } from 'r3f-xr-widgets'

<mesh onPointerDown={(e) => vibrateOnEvent(e)}>
  <boxGeometry />
</mesh>

// Custom intensity and duration
<mesh onPointerDown={(e) => vibrateOnEvent(e, { value: 0.8, duration: 100 })}>
  <boxGeometry />
</mesh>

Released under the MIT License.