Pick objects in XR

https://playground.babylonjs.com/#6XSQG1#8

I’m trying to pick objects in XR on Cardboard. The playground code above works fine in XR emulation mode on desktop, but not in true XR on mobile. There seems to be some y offset issue, clicking below the plane finds it.

Is this a bug, or do I need to use pick differently in true XR?

@RaananW one for you?

Many thanks in advance.

Hi CarlBateman,

I haven’t had a chance to test this, but I noticed that your picking code is going directly through the arithmetic center of the canvas. Are you sure that’s the right place for it to go, indicative of where the cursor actually is in XR? To test this, it might be worth trying pickWithRay instead of pick and using the HMD forward ray provided by XR, which I believe is also the basis for the cursor.

I’ve updated the playground to use pickWithRay (https://playground.babylonjs.com/#6XSQG1#9) but get the same result. :confused:

This is interesting. I’ve tried it out a little bit now to simplify a few things and validate behavior with some debug shapes. I now get the ray I expect, which I wasn’t getting without a few modifications; but, interestingly, I’m still getting the behavior you describe. At this point, it certainly feels like a bug, but I don’t have a good explanation for what’s happening, and I’m unfamiliar enough with this code and this approach (most XR picking is done with hands, not gaze) that it’s very possible there’s something I’m overlooking or doing wrong. @RaananW, is the Playground I linked to behaving the way it’s expected to?

I’ll look into it. Just as a test, have you tried using one of the eye cameras? Left or right camera?

I made several mistakes with my pickWithRay version.

This playground (https://playground.babylonjs.com/#6XSQG1#17) seems to work.
So problem solved.
Thanks @syntheticmagus

1 Like