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

This image should describe it better:
https://i.imgur.com/Y2eCePe.png

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.name = 'earth'

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

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

with:

๐›Œ < 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)

3 Likes

For walking - view in codepen.

1 Like