three.js set and read camera look vector

The camera does not have a “look vector”, so you cannot set it.

You can, however, construct a point to look at by adding your look vector to the camera’s position, and then calling

camera.lookAt( point );

Here is how to determine the direction in which the camera is looking, assuming the camera either has no parent (other than the scene).

The camera is looking down its internal negative z-axis, so create a vector pointing down the negative z-axis:

var vector = new THREE.Vector3( 0, 0, - 1 );

Now, apply the same rotation to the vector that is applied to the camera:

vector.applyQuaternion( camera.quaternion );

The resulting vector will be pointing in the direction that the camera is looking.

Alternatively, you can use the following method, which works even if the camera is a child of another object:

camera.getWorldDirection( dirVector );

three.js r.73

Leave a Comment