Jump to content

Enabling VR on my project


Nesh108
 Share

Recommended Posts

Hello!

I am working on a little project and I have been using the standard 'BABYLON.FreeCamera' as a smoothCamera following the player. All easy and good.

Now, I would like to add VR support for people using their phones and a VR headset.

I looked around and found this:

camera = new BABYLON.DeviceOrientationCamera('camera', new BABYLON.Vector3(0, 0, 0), scene);
camera.setCameraRigMode(BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL, {interaxialDistance: 0.0637});

This works as in splitting the screen in half (VR-style) but it doesn't follow the player anymore. How comes? Is there a way to just have the exact same behaviour of my smooth camera but just having the possibility to look around with the headset instead of using the mouse?

Also, I noticed that I had to enable WebVR on my Chrome flags to get it to work. Is there a way to avoid that? Having to tell people to go and do that is just ugly and probably they won't do it, especially on mobile.

 

Thanks!

Link to comment
Share on other sites

Hello,

You should use directly our VR camera instead such as the WebVRFreeCamera or VRDeviceOrientationFreeCamera based on feature detection.

Here's a basic sample: http://www.babylonjs-playground.com/#IHY77X#2

Regarding browsers support, on desktop, only MS Edge has WebVR enabled by default today on Windows 10 Creators Update, Firefox 55 will also soon (august) and Chrome should by the end of the year. On mobile, only Android & Chrome has it.

That's why you should fallback to the Device Orientation camera most of the time. 

David

Link to comment
Share on other sites

Hey @davrous,

I have checked the PG and it worked on my phone. Now I am trying to add it to my project.

The WebVRFreeCamera doesn't seem to work at all (probably that requires an actual headset which I don't have) but the VRDeviceOrientation looks right. The main problem is that it doesn't seem to follow my player anymore.

I set the parent of the camera but it looks like it is disregarded, so I can kind of look around but the camera won't follow the player anymore. Is that normal? The code is exactly the same, I am just changing the camera.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...