Skip to content Skip to sidebar Skip to footer

Unable To Change Camera Position When Using Vrcontrols

I have the following code: ... camera = new THREE.PerspectiveCamera(75, screenRatio, 1, 10000 ); camera.position.z = -10; // position.set(0, 0, -10) also not working. controls = ne

Solution 1:

Found the solution inside Sechelt demo from Mozilla VR Team demos. I'll put here a code snippet as reference for other VR beginners.

Adding the camera to a group instead of updating the camera position directly is the way to move the camera.

var scene, renderer, cameraRatio, camera, controls, effect, dolly;

functioninit() {
    scene = newTHREE.Scene();

    renderer = newTHREE.WebGLRenderer({ antialias: true });
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );

    cameraRatio = window.innerWidth / window.innerHeight;
    camera = newTHREE.PerspectiveCamera( 75, cameraRatio, 1, 1000 );       

    controls = newTHREE.VRControls( camera );
    effect = newTHREE.VREffect( renderer );
    effect.setSize( window.innerWidth, window.innerHeight );

    // This helps move the camera
    dolly = newTHREE.Group();
    dolly.position.set( 0, 0, 0 );
    scene.add( dolly );
    dolly.add( camera );

    ...
    // Of course, there should be lights, objects, etc
}

functionanimate() {
    dolly.position.x += 0.1;
    controls.update();
    effect.render( scene, camera );
}

init();
animate();

Solution 2:

I think the camera is now the object. You can try object.position.set() instead.

Post a Comment for "Unable To Change Camera Position When Using Vrcontrols"