0

I want to programmatically move the position of the view in a webvr scene. To do this I am using the position.add method.

Here is how I move the camera programmatically:

 <a-entity position="33 0 -33" rotation="0 180 0" look-controls id="camera" 
       camera="userHeight: 1.6" listener></a-entity>

Camerage is moved here:

 var obj3d = document.querySelector("#camera").object3D;
 var angleobj = obj3d.getWorldDirection();
 angleobj.y = 0;
 obj3d.position.add(angleobj.multiplyScalar(0.004*3));

This works in normal mode, but in cardboard mode, the camera is not moving. How can I move the camera in cardboard view mode programmatically?

1
  • Rotate a wrapper entity versus the camera directly. Commented Dec 12, 2017 at 10:53

1 Answer 1

1

As far as i know, once you switch to the "VR mode", you get to use other camera than the one outside of "VR mode".

I think You should listen for the VR enter / exit events, and change the camera reference:

this.el.sceneEl.addEventListener('enter-vr',() => {
     obj3d = document.querySelector("#camera").object3D;
}
this.el.sceneEl.addEventListener('exit-vr',() => {
     obj3d = document.querySelector("#camera").object3D;
}


Please rethink, if this is necessary, when the user moves his head, and the camera goes wild, it can get really dizzy, really fast.

A-frame's Diego Marcos in his anwsers often recommends visual indications WHERE to look, instead of such options.


If the above does not work, try grabbing the camera entity, instead if its object3D:

var obj3d = document.querySelector("#camera");

and move it using the setAttribute() method

obj3d.setAttribute("position", {x: _x, y: _y, z: _z});
Sign up to request clarification or add additional context in comments.

1 Comment

i implemented your suggestion. the enter/exit-vr events are detected but it still doesn't work in the full view. any ideas how to make this work?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.