Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aframe - Set camera position at runtime

Tags:

aframe

webvr

In a a-scene, I try to change my camera position at runtime. The DOM property changes but the camera does not move.

What could have I missed ?

my js code: document.querySelector('#myCameraPosition').setAttribute('position', '0 0 0');

My a-scene:

    <a-entity id="myCameraPosition" position="0 0 50">
        <a-entity id="myCamera" camera look-controls keyboard-controls>
        </a-entity>
    </a-entity>
like image 961
clement_at_openindoor.io Avatar asked Apr 17 '16 14:04

clement_at_openindoor.io


3 Answers

Create a wrapper entity around the camera:

<a-entity id='cameraWrapper' position="0 0 0">
  <a-camera></a-camera>
</a-entity>

Then change position of the wrapper:

document.querySelector("#cameraWrapper").object3D.position.set(1, 1, 1);
like image 90
ngokevin Avatar answered Nov 09 '22 04:11

ngokevin


Had to set "look-controls" to false for javascript rotation control, otherwise wouldn't work :

function resetView(el){
  el.setAttribute('look-controls','false');
  el.setAttribute('rotation',{x:0,y:0,z:0});
  el.setAttribute('look-controls','true');
}
like image 21
Laurie Clark Avatar answered Nov 09 '22 04:11

Laurie Clark


On the example below I can change the position of the camera entity's parent and it works as expected:

https://aframe.io/examples/showcase/helloworld/

Is any of the openearthview or acceleration components writing the position of the camera entitiy's parent? They might be overwritting its position.

like image 1
Diego Marcos Avatar answered Nov 09 '22 06:11

Diego Marcos