JS Scripts not working when entering VR Mode

I don’t know why but whatever script I have such as the first person camera below, as soon as I enter VR mode, it will simply not work. Just in a full window, the script works fine, can someone tell me where I went wrong? I have a standard Player entity with rigid body and collision and a VR camera attached to it. Thanks in advance.

var Player = pc.createScript('player');

Player.prototype.initialize = function() {

    this.camera = this.app.root.findByName('Camera');
    this.direction = new pc.Vec3();
    this.MOVE_SCALE = 60;

Player.prototype.update = function() {

    if ((this.app.keyboard.isPressed(pc.KEY_W)) || (this.app.keyboard.isPressed(pc.KEY_UP))) {

        this.direction.y = 0;

    } else if ((this.app.keyboard.isPressed(pc.KEY_S)) || (this.app.keyboard.isPressed(pc.KEY_DOWN))) {

        this.direction.y = 0;

    } else if ((this.app.keyboard.isPressed(pc.KEY_D)) || (this.app.keyboard.isPressed(pc.KEY_RIGHT))) {

        this.direction.y = 0;

    } else if ((this.app.keyboard.isPressed(pc.KEY_A)) || (this.app.keyboard.isPressed(pc.KEY_LEFT))) {

        this.direction.y = 0;


Can you provide a link to the project please? I think I have a rough idea on what could be the problem but I need to check the project setup.

Also, what VR setup do you have for this?

Ok, thanks for helping, here is the link: https://playcanvas.com/editor/scene/526347

I’m just using a mobile viewer, nothing too special.

From what I can see, the keyboard events are not firing when you are in VR. I’m not sure if this is from the PlayCanvas or from the WebVR polyfill or even Chrome prevent the keyboard events.

I can’t seem to find anything on the Internet that confirms this though.

Thank you for the effort! If anyone knows anything please let me know.

Ok guys, I have find out that it has something to do with the new Daydream viewer in Chrome. The older viewer in other browsers, I just tested Opera, seem to work fine with the scripts. Anyone have any insight?

TBH, if you are thinking of doing something like this (user input to move around), I would advise in using the GamePad API.

The reasons for this are:

  • Usability - Much easier to use without being able to look at it compared to a keyboard
  • The Gear VR (both on the on the headset and the separate controller), Daydream controllers and Vice/Rift controllers are exposed in the GamePad API

Thanks, I will have a look at it. Do you think a generic controller from eBay would work with this?

A PS4 controller will work if you if you have one kicking about. AFAIK, most bluetooth controllers ‘should’ work but don’t hold me to this as there could be some issues. Just buy one that says ‘compatible with Android’ and you ‘should’ be fine.

The one I bought apparently has a “mouse”, “game” and also “keyboard” mode. I’m guessing the “game” mode should work.