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.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; = 10; = 1000;

    scene.add( spotLight );,0,200);;

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
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( );

As an option: Lights for car headlight

1 Like