Change spotLight position

hi I Have a car model in my scene and i want to use spot light for its headlight so that it cast light in front of the car on the ground but my problem is that i can’t change position or rotation of the spotLight.I’ve tested position and target position but i couldn’t figure out its logic.

here’s my scene:

i want to move lights position to car’s front.
sorry for my poor language :slight_smile:

here’s my code:

spotLight = new THREE.SpotLight( 0xff0000, 10 );

    // scene.add( spotLight.target );

    spotLight.position.set(0,0,-1);

    spotLight.angle = Math.PI / 4;

    spotLight.penumbra = 0.05;

    spotLight.decay = 2;

    spotLight.distance = 1000;

    spotLight.intensity = 2;

    spotLight.castShadow = true;

    spotLight.shadow.mapSize.width = 1024;

    spotLight.shadow.mapSize.height = 1024;

    spotLight.shadow.camera.near = 10;

    spotLight.shadow.camera.far = 1000;

    scene.add( spotLight );

    spotLight.target.position.set(0,0,200);

    spotLight.target.updateMatrixWorld();

A small demo for you.

  1. You can add spotlight directly to the model of the car (model.add(spotLight). This way you can position the light relatively to the position of the car - so when the car rotates, headlights will rotate automatically with it.
  2. When spotlight is placed relatively to the car, it’ll also simplify setting target - since you can just set it to spotlight position + vec3(0, 0, 1) - and they will always point forwards.
  3. Please see docs about Spotlight.target:
Note: For the target's position to be changed to anything other than the default, it must be added to the scene using:

scene.add( light.target );
2 Likes

As an option: Lights for car headlight

1 Like