Browse Source

Camera position when entering XR

Make sure position is copied from the main scene camera when entering XR

Fixing https://github.com/BabylonJS/Babylon.js/issues/7158
Raanan Weber 5 years ago
parent
commit
461048ce3f
1 changed files with 4 additions and 2 deletions
  1. 4 2
      src/Cameras/XR/webXRExperienceHelper.ts

+ 4 - 2
src/Cameras/XR/webXRExperienceHelper.ts

@@ -138,13 +138,15 @@ export class WebXRExperienceHelper implements IDisposable {
             // Wait until the first frame arrives before setting state to in xr
             // Wait until the first frame arrives before setting state to in xr
             this.sessionManager.onXRFrameObservable.addOnce(() => {
             this.sessionManager.onXRFrameObservable.addOnce(() => {
                 this._setState(WebXRState.IN_XR);
                 this._setState(WebXRState.IN_XR);
+
+                this.setPositionOfCameraUsingContainer(new Vector3(this._nonVRCamera!.position.x, this.camera.position.y, this._nonVRCamera!.position.z));
             });
             });
 
 
             return this.sessionManager;
             return this.sessionManager;
         }).catch((e: any) => {
         }).catch((e: any) => {
             console.log(e);
             console.log(e);
             console.log(e.message);
             console.log(e.message);
-            throw(e);
+            throw (e);
         });
         });
     }
     }
 
 
@@ -180,4 +182,4 @@ export class WebXRExperienceHelper implements IDisposable {
         this.onStateChangedObservable.clear();
         this.onStateChangedObservable.clear();
         this.sessionManager.dispose();
         this.sessionManager.dispose();
     }
     }
-}
+}