Skip to content

<RayGrab /> with blocked axis? #230

Discussion options

You must be logged in to vote

If you create an issue, I'll be sure to get back to it.

Three's matrix system is a bit of a mess, but this importantly only works in local space, applying world-space transforms from the controller:

https://github.com/pmndrs/react-xr/blob/93d0e4c44676fd52c850dd80eafa8bc40bb83fef/src/Interactions.tsx#L222-L232

So we can memoize whichever axis shouldn't be moved and reapply it:

useFrame(() => {
  const controller = grabbingController.current
  const group = groupRef.current
  if (!controller) return
  
  // Memoize original values
+  const [x, y, z] = group.position

  group.applyMatrix4(previousTransform)
  group.applyMatrix4(controller.matrixWorld)

  // Keep original z value
+  group.pos…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@JenniferFalkenstein
Comment options

@CodyJasonBennett
Comment options

Answer selected by bbohlender
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants