Recently I started experimenting with Three.js and I’m currently working on a project where I need to position a SpotLight at the same coordinates as the camera. Below is the code snippet I’m using:
$(document).ready(function() {
init();
});
function init() {
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set(50, 10, 0);
camera.lookAt(new THREE.Vector3(0, 0, 0));
var spotLight = new THREE.SpotLight( 0xffffff );
spotLight.position = camera.position;
console.log(camera.position);
console.log(spotLight.position);
}
Upon running this code, the output shows camera.position as 50,10,0 (as expected) but surprisingly, spotLight.position reads 0,1,0 instead of also being 50,10,0 even though I explicitly set it to mirror the camera's position?