Attaching object to vr/xr camera

Hi everyone
First of all, sorry for my bad english.
I’ve been trying to attach objects(meshes) to the webvr camera. So I want the object to be always at the same position in front of the player regardless of players pose. I tried setParent(), tried to set the position of the object in front of the camera every frame(tried it with onEveryFrameTrigger and registerBeforeRender). It worked for non-vr camera as expected but not for the vr camera.
Is there a proper way to do it or is it impossible in the first place?

cc @RaananW

it should be very much possible. Want to share a playground?

Sure I want it!

I am not quite sure but your answere sounds a bit ‘lost in translation’ :thinking: :sweat_smile:
For my understanding, RaananW is asking you to save an example from your code in the playground and share it here in the thread, so that he can look into it and help you!

If I got this wrong, forgive me! :raised_hands: Just want to save you guys a bit time… :sweat_smile:

1 Like

Nope, exactly that :slight_smile:

@hahaha - show me how your scene looks like, and I will be able to find out what’s going on

Sorry guys my mistake.
Here is an example.

The code between the lines “//%%%%%%%%%%%%%%%%%%” are added in the existing example for attaching the sphere to the camera. As you can see the sphere is attached firmly to the camera on non-vr mode.

Your example is using the WebVR experience helper, which is deprecated and should not be used. I just marked it accordingly in our documentation as well.

When you set the mesh’s parent to the camera, you are setting it to the desktop’s camera. When entering XR you are using a different camera object, so that you need to set the mesh’s parent to be that camera instead.

In WebXR it would look something like this:

Thanks for your immediate reply.
A thing I don’t understand is how to get into the XR Mode. When using vr helper, I see a button for vr mode in the bottom of the right side of the monitor. And why is it some playground exmaples for webWR just show a white screen?

WebVR is deprecated and doesn’t work in practically any browser. What browser / device are you using to test that?

It works on Chrome on my android phone but not on Firefox. I found out there was webXR emulator addon for Firefox on pc. Thanks!

1 Like

Firefox is the last browser that still has webvr implemented. I do hope it is going to change very soon, as WebVR is not used anywhere. WebXR is the future of immersive web :slight_smile:

1 Like

Thanks again!

1 Like