Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
fix update to haptics system
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Jun 19, 2024
1 parent baf183f commit f220566
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions packages/spatial/src/xr/XRHapticsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ import { defineActionQueue } from '@etherealengine/hyperflux'
import { InputSourceComponent } from '../input/components/InputSourceComponent'
import { XRAction } from './XRState'

/** haptic typings are currently incomplete */

declare global {
interface Gamepad {
/** @deprecated - old meta quest API */
hapticActuators?: Array<{
/**
* @param value A double representing the intensity of the pulse. This can vary depending on the hardware type, but generally takes a value between 0.0 (no intensity) and 1.0 (full intensity).
* @param duration A double representing the duration of the pulse, in milliseconds.
*/
pulse: (value: number, duration: number) => void
}>
}
}

const inputSourceQuery = defineQuery([InputSourceComponent])

const vibrateControllerQueue = defineActionQueue(XRAction.vibrateController.matches)
Expand All @@ -40,12 +55,15 @@ const execute = () => {
for (const action of vibrateControllerQueue()) {
for (const inputSourceEntity of inputSourceQuery()) {
const inputSourceComponent = getComponent(inputSourceEntity, InputSourceComponent)
if (inputSourceComponent.source.handedness === action.handedness) {
if (inputSourceComponent.source.gamepad && inputSourceComponent.source.handedness === action.handedness) {
if ('hapticActuators' in inputSourceComponent.source.gamepad) {
// old meta quest API
inputSourceComponent.source.gamepad.hapticActuators?.[0]?.pulse(action.value, action.duration)
continue
}

const actuator = inputSourceComponent.source.gamepad?.vibrationActuator
if (!actuator) continue
if (Array.isArray(actuator))
// old meta quest API
actuator[0].pulse(action.value, action.duration)
else actuator.playEffect('dual-rumble', { duration: action.duration })
}
}
Expand Down

0 comments on commit f220566

Please sign in to comment.