VR experience collisions not working

I have a scene created in blender and exported in babylon js is rendering it with collisions and gravity enabled. But once I enable Default Vr Experience the collision and gravity gets disabled. What’s the solution for this I need my collsion and gravity to work with vr also.

This shouldn’t happen. Want to share a playground so we can check?

First of all sorry for the late reply… Due to some privacy reasons i cant share the code of my project. But i saw the same problem while using the sponza example of the babylon js.

on using vr the gravity and the collisions gets disabled else its okay.

I have to admit that i don’t have a working VR environment, only XR… but that might be the issue here. What browser are you using? VR is deprecated on chrome, and the vr experience helper falls back to WebXR. Are you enabling collisions on all VR/XR cameras in the scene?

I am using the scene.createDefaultVRExperience() function for VR. There I guess we need not enable seperate collision…

Can you elaborate on your scene a little bit? Share some code?

Hello RaananW,
So I basically have 3 scenes and each scene has a door from which you can transition between scenes. So with a Universal camera in each scene all works fine but when I switch to VR using the createdefaultVRExperience the collisions and gravity is not present. I also tried to take the vrcamera from the defaultExperience variable and tried to set the property but it showed error " Cannot set property ‘applyGravity’ of undefined";

Below is the code snippet:

var camera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(0, -8, -20), scene);
camera.attachControl(canvas, true);
camera.checkCollisions = true;
camera.applyGravity = true;

var vrexp =  scene.createDefaultVRExperience({createDeviceOrientationCamera:false});

var vrcam = vrexp.webVRCamera;
vrcam.applyGravity = true;

A few things:

  1. I am going back to my second message, explaining about webxr and webvr. It is possible that the webvr camera is not available if you are using chrome
  2. A VR camera is not like a regular camera where you can stop its movement. The movement is real life will be copied to the virtual environment. You as a developer need to make sure the user has enough room to move around, and that you notify the user of collisions (or move the world accordingly). There is no simple way of making sure a user doesn’t walk through walls.

please try the sponza example on vr on browser…The collision doesnt work in that mode

Answering that it doesn’t work, after i explained why it is not working is not gonna help either of us.
Please read my last message again and see if it explains the issue.

If it doesn’t, here is a list of questions, please answer them if you want us to be able to help further:

  1. what browser are you using to test the VR scene
  2. What is the expected behavior, and what is NOT working. Are you walking through the floor? are you walking through walls? are objects falling down? are objects not colliding?

The answer to 2 should be a LOT more than a sentence. And preferably (or arguably mandatory) will include a playground, a screencast, images, or anything else that will help us understand what the problem is.

1 Like

I second that

First of all thank you @RaananW for helping me out with this.
Okay to answer your questions.

  1. I am using Google Chrome for testing the Vr scene. I tested it in Mozilla also the results were the same.
  2. To answer your second question. I have created a modified version of the planet example which shows how to use collision and gravity. In this example I have also included the default vr experience. Please go through it and you will notice that while using the normal camera collisions and gravity work fine and while switching to vr there is no gravity or collisions enabled and there is a commented line of code for checkcollisions which on uncommenting gives error.

Link : https://playground.babylonjs.com/#283GH6#3

Thank you for your help :).

So if I get you correctly, you can walk through the box which is the problem?

As I wrote before, this is impossible in VR. If you want to push the box you will need to use physics instead, or implement some form of collision mechanism that moves the box instead of limit the camera.

Notice also that you didn’t set the floor as a floor mesh in VR, so you can’t teleport anywhere

1 Like