Pointerlock with createDefaultVRExperience in deviceOrientationCamera mode

I’m developing a simple VR game to be played in VR or as normal. How do I enter PointerLock mode when not in VR mode?
TIA

engine.enterPointerlock() would normally do the trick.

Sadly,
engine.enterPointerlock();
raises the error
TypeError: engine.enterPointerlock is not a function

However,
scene.getEngine().isPointerLock = true;
sort of works – the camera tracks, but the cursor is also visible.

enterPointerLock is for 4.1 only

You can also do it manually on 4. with canvas.requestPointerLock()

1 Like

OK. Then the question becomes, where do I call it?
I tried calling it from onExitingVRObservable and onExitingVR

vrHelper.onExitingVRObservable.add(() => {
   setTimeout(() => {
    canvas.requestPointerLock();
  }, 1000);
});

but neither worked (I added the timeout because I thought it might be the same issue as Virtual Reality bugs when I enable Interactions on Microsoft Edge+Safari).

I can invoke pointer lock elsewhere, however e.g.

scene.onKeyboardObservable.add((kbInfo) => {
  switch (kbInfo.type) {
    case BABYLON.KeyboardEventTypes.KEYUP:
      canvas.requestPointerLock();
      break;
  }
});

TIA

Pinging @RaananW for the VR part. But what is your use case here?

I want the game to work both in VR and not (so on desktop and on mobile VR/not VR*). It will help with testing, too.
* What is the opposite of VR???

well when not in vr you can ask the engine to go fullscreen (and use the engine.enterFullscreen(true)

I think the issue here is the fullscreen and not the pointer lock, no?
When exiting VR you want to go fullscreen, with pointerlock enabled. But this requires a user interaction (such as a click), and will be impossible to enable upon exiting VR.
My suggestion (which will also be good for your players, IMHO) is to add a "pause screen"after exiting VR, with something like “click here to continue playing”. This will also enable the user to takke off the VR device comfortably, with no stress. And will solve all of your other problems as well :slight_smile:

I hadn’t even considered full-screen, but it likes I’ll need some workaround as you suggest.

1 Like