Raycast collisions with xr controller not working

I’m able to get raycast collision detection working in my scene when using a mouse, as depicted in the first codeblock below. However, I haven’t been able to get a raycaster to intersect with objects in my scene while in WebXR using my oculus controllers (using the code in the second codeblock below). The only detections I was getting were the objects in the controller itself, like the beam line and thumbstick, so at least I know that the raycaster is pointing in a direction…

I’ve been working at this problem for over a week and I just can’t seem to lick it. I’m eager to get this solved. Thanks!

Intersection detection using a mouse (working):

let raycaster = new Raycaster();
let pickedObject = null;
// cast a ray through the frustrum
raycaster.setFromCamera(this.pointer, this.camera)
let intersectioned = raycaster.intersectObjects(this.scene.children)
if(intersectioned.length){
      console.log(intersectioned)
}

Intersection detection using a VR controller (not working)

// cast a ray from the controller
let raycaster = new Raycaster();
this.tempMatrix.identity().extractRotation( this.xrCtlRight.controller.matrixWorld );
raycaster.ray.origin.setFromMatrixPosition( this.xrCtlRight.controller.matrixWorld );
raycaster.ray.direction.set( 0, 0, -1 ).applyMatrix4( this.tempMatrix )

const intersections = raycaster.intersectObjects( this.scene.children );
if( intersections.length ){
      for( let i=0; i<intersections.length; i++ ){
            if(intersections[i].object.name !== 'xrControllerRaycastBeam' && intersections[i].object.name !== 'thumbstick' && intersections[i].object.name !== 'controller'){
                        console.log(intersections[i])
            }
      }
}

If three.js webxr dragging example is working for you, you can compare your code to see what’s different.

Wonderful, yes that example is working for me. I somehow missed that example! Will see what I can do and follow up :slight_smile:

@anidivr thanks again for sharing that example with me. I’ve managed to get it to work in my project :slight_smile: