react-xr icon indicating copy to clipboard operation
react-xr copied to clipboard

Docs: `useXRControllerLocomotion` rapier example is outdated

Open kwaa opened this issue 7 months ago • 5 comments

https://pmndrs.github.io/xr/docs/getting-started/all-hooks#usexrcontrollerlocomotion

rotationInfo: Euler is now rotationVelocityY: number.

kwaa avatar May 10 '25 06:05 kwaa

Thanks. I'm assuming this will be fixed with the new technical docs rewrite from @taeuscherpferd

bbohlender avatar May 10 '25 08:05 bbohlender

Thanks. I'm assuming this will be fixed with the new technical docs rewrite from @taeuscherpferd

I noticed that #425 no longer seems to contain the rapier example.

kwaa avatar May 11 '25 07:05 kwaa

@taeuscherpferd just to ping you here so we can make sure the rapier example with controller locomotion is not lost :)

bbohlender avatar May 11 '25 18:05 bbohlender

I wrote a new Rapier example referencing the Minecraft example:

import type { RapierRigidBody } from '@react-three/rapier'
import type { Vector3 } from 'three'

import { CapsuleCollider, euler, quat, RigidBody } from '@react-three/rapier'
import { useXRControllerLocomotion, XROrigin } from '@react-three/xr'
import { useRef } from 'react'

export const UserMovementWithPhysics = () => {
  const userRigidBodyRef = useRef<RapierRigidBody>(null)

  useXRControllerLocomotion((velocity: Vector3, rotationVelocityY: number) => {
    if (!userRigidBodyRef.current)
      return

    userRigidBodyRef.current.setLinvel({ x: velocity.x, y: 0, z: velocity.z }, true)
    userRigidBodyRef.current.setRotation(quat(userRigidBodyRef.current.rotation()).multiply(quat().setFromEuler(euler().set(0, rotationVelocityY, 0, 'YXZ'))), true)
  })

  return (
    <RigidBody
      canSleep={false}
      colliders={false}
      enabledRotations={[false, false, false]}
      position={[0, 2, 0]}
      ref={userRigidBodyRef}
      type="dynamic"
    >
      <CapsuleCollider args={[0.3, 0.5]} />
      <XROrigin position={[0, -1, 0]} />
    </RigidBody>
  )
}

kwaa avatar May 12 '25 04:05 kwaa

@taeuscherpferd just to ping you here so we can make sure the rapier example with controller locomotion is not lost :)

I'll be sure to add it to my priority stack of TODOs 👍

taeuscherpferd avatar May 12 '25 11:05 taeuscherpferd