Skip to content

Add shared haptics helper and mobile vibration fallback in api/xr.js#353

Open
tracygardner wants to merge 2 commits intomainfrom
codex/add-shared-haptics-helper-in-api/xr.js
Open

Add shared haptics helper and mobile vibration fallback in api/xr.js#353
tracygardner wants to merge 2 commits intomainfrom
codex/add-shared-haptics-helper-in-api/xr.js

Conversation

@tracygardner
Copy link
Contributor

Motivation

  • Provide a single shared haptics entrypoint to centralize gamepad haptics and a mobile vibration fallback in api/xr.js.
  • Ensure existing controller rumble APIs behave sensibly on phones by mapping gamepad motors/patterns to the Vibration API when no gamepad actuator is available.

Description

  • Added a new helper triggerHaptics that attempts gamepad haptics via vibrationActuator.playEffect("dual-rumble", ...) first, and falls back to navigator.vibrate(...) if no suitable actuator is found.
  • Refactored controllerRumble to call triggerHaptics and map mobile behavior to a single vibration duration (ignoring left/right motors on phones).
  • Refactored controllerRumblePattern to build scheduled gamepad effects and a corresponding vibration array ([on, off, on, off, ...]) for the mobile fallback.
  • Refactored playRumblePattern to convert entries in rumblePatterns (using each pulse's duration and pauseAfter) into both gamepad effects and a vibration-array timing for navigator.vibrate, while keeping behavior noop-safe when neither API is available.

Testing

  • Ran node --check api/xr.js which completed without errors.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant