Reputation: 663
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?
Upvotes: 0
Views: 275
Reputation: 14645
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;
}
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});
Upvotes: 1