Skip to content

Commit

Permalink
fix minecraft example controller left & right
Browse files Browse the repository at this point in the history
  • Loading branch information
bbohlender authored Aug 14, 2024
1 parent c854c78 commit c4b75b1
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions examples/minecraft/src/VRPlayerControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,28 @@ export function VRPlayerControl({
}) {
const originRef = useRef<THREE.Group>(null)

const controllerLeft = useXRControllerState('right')
const controllerRight = useXRControllerState('left')
const controllerLeft = useXRControllerState('left')
const controllerRight = useXRControllerState('right')

useFrame((state, delta) => {
if (controllerRight != null) {
const thumbstick = controllerRight.gamepad?.['xr-standard-thumbstick']
if (originRef.current != null && thumbstick?.xAxis != null && thumbstick.xAxis != 0) {
originRef.current.rotateY((thumbstick.xAxis < 0 ? 1 : -1) * TURN_SPEED * delta)
}
const thumbstickLeft = controllerLeft?.gamepad?.['xr-standard-thumbstick']
if (originRef.current != null && thumbstickLeft?.xAxis != null && thumbstickLeft.xAxis != 0) {
originRef.current.rotateY((thumbstickLeft.xAxis < 0 ? 1 : -1) * TURN_SPEED * delta)
}

if (controllerLeft?.gamepad?.['a-button']?.state === 'pressed') {
playerJump?.()
}

const thumbstick = controllerLeft?.gamepad['xr-standard-thumbstick']
if (thumbstick?.xAxis != null && thumbstick.yAxis != null) {
const thumbstickRight = controllerRight?.gamepad['xr-standard-thumbstick']
if (thumbstickRight?.xAxis != null && thumbstickRight.yAxis != null) {
state.camera.getWorldQuaternion(helpers.quaternion)

playerMove?.({
forward: thumbstick.yAxis < 0,
backward: thumbstick.yAxis > 0,
left: thumbstick.xAxis < -THUMBSTICK_X_WIGGLE,
right: thumbstick.xAxis > THUMBSTICK_X_WIGGLE,
forward: thumbstickRight.yAxis < 0,
backward: thumbstickRight.yAxis > 0,
left: thumbstickRight.xAxis < -THUMBSTICK_X_WIGGLE,
right: thumbstickRight.xAxis > THUMBSTICK_X_WIGGLE,

// rotation: state.camera.rotation
rotation: helpers.euler.setFromQuaternion(helpers.quaternion),
Expand Down

0 comments on commit c4b75b1

Please sign in to comment.