Skip to content

Commit

Permalink
feat: controller binding
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Oct 6, 2024
1 parent 9f79502 commit 4ffcbbf
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/components/xr/origin.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
import type { Group } from 'three'

import { useControllerLocomotion, XROrigin } from '@react-three/xr'
import { useFrame } from '@react-three/fiber'
import {
useControllerLocomotion,
// useXRControllerButtonEvent,
useXRInputSourceState,
XROrigin,
} from '@react-three/xr'
import { useRef } from 'react'

import { useTogglePlaying } from '../../contexts/playing'

export const Origin = () => {
const togglePlaying = useTogglePlaying()
const ref = useRef<Group>(null)

/** @see {@link https://developers.meta.com/horizon/blog/button-action-mapping-user-inputs-controller-meta-quest-horizon-developers-vr-mr/} */
const controllerRight = useXRInputSourceState('controller', 'right')

useControllerLocomotion(ref)

useFrame(() => {
if (!controllerRight?.gamepad)
return

if (controllerRight.gamepad['a-button']?.state === 'pressed') {
// TODO: jump
}

if (controllerRight.gamepad['b-button']?.state === 'pressed') {
togglePlaying()
}
})

/**
* TODO: rapier physics
* @see {@link https://pmndrs.github.io/xr/docs/getting-started/all-hooks#usecontrollerlocomotion}
Expand Down

0 comments on commit 4ffcbbf

Please sign in to comment.