Trying to add a flashlight effect using Three.js r105
I'm attempting to attach a SpotLight
to the camera to achieve a "Flashlight" effect. However, once I connect the SpotLight
to my Camera
, the light seems to completely stop working. What could be the issue here?
Interestingly, the LightHelper
appears to be functioning properly. Additionally, when I add the SpotLight
independently to the Scene
, everything works as expected.
But as soon as I link the SpotLight
to the Camera
, there is no sign of even the smallest hint of light
const cameraLight = new THREE.SpotLight(0xffffff, 4, 40);
cameraLight.castShadow = true;
cameraLight.shadow.bias = -0.0001;
cameraLight.shadow.mapSize.width = 512;
cameraLight.shadow.mapSize.height = 512;
cameraLight.shadow.camera.near = 0.1;
cameraLight.shadow.camera.far = 500;
var d = 32;
cameraLight.shadow.camera.left = -d;
cameraLight.shadow.camera.right = d;
cameraLight.shadow.camera.top = d;
cameraLight.shadow.camera.bottom = -d;
cameraLight.visible = true;
cameraLight.distance = 40;
cameraLight.decay = 1;
cameraLight.angle = Math.PI/2;
cameraLight.penumbra = 0.1;
camera.add( cameraLight );
cameraLight.position.set( 0, 0, 1);
cameraLight.target = camera;
var cameraLightHelper = new THREE.PointLightHelper( cameraLight, 5, 0x00ff00 );
scene.add( cameraLightHelper );
scene.add( camera );