Making a light source follow an object

If you've got a moving object in the scene that you want to highlight with a spotlight, you need to be able to change the direction a light is pointed at. In this recipe, we will show you how to do just that. We will show you how you can keep THREE.SpotLight pointed at a moving object in the scene.

Getting ready

There are no steps that you need to take to run this recipe. You can see the final result of this recipe by opening up the 05.07-make-a-light-follow-object.html example in your browser. You will see something similar to the following screenshot:

Getting ready

In this example, you can see a sphere that moves from left ...

Get Three.js Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.