How can a light source be fixed behind an object, but with camera movement?

This image should describe it better:

The camera is viewing always at earth.
If I move the camera, the light should always point from behind the earth/sphere, towards it.

Whatever I try, it’s either on a fixed place, or in-front of the camera.

In theory, after adding a light to the sphere, maybe I can use some camera.position values inside position.set()?

E.g. this one also stays in one position and doesn’t update:

const earth = globe.scene().children.find((obj3d) => obj3d.type === 'Group'); = 'earth'

      const pLight = new THREE.PointLight( 0xffffff, 1 );
      pLight.position.copy(camera.position) = earth; 
      scene.add( );

Any help appreciated

Hi! I think need always to calculate normalized vector from camera to sphere, then from sphere position add this vector multiply on distance like 2 meters for light position. And if it is spot light then spot.lookAt(sphere.position);

1 Like

Compute direction vector dir from camera to earth as

dir = earth.pos - camera.pos

A line that extends both ways to infinity through camera and earth can be described as

L = camera.pos + π›Œ * dir


π›Œ < 0 : positions behind the camera (when looking at earth)
π›Œ = 0 : position at camera
0 < π›Œ < 1 : positions between camera and earth
π›Œ = 1 : position at earth
π›Œ > 1 : positions beyond earth (when looking at earth)


For walking - view in codepen.

1 Like