Graphics Reference
In-Depth Information
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:
In this example, you can see a sphere that moves from left to right and back again.
THREE.SpotLight in this scene follows the position of this sphere so that it is al-
ways pointed directly at the center of that object.
How to do it...
Following an object in Three.js is very easy and only takes a couple of easy steps:
1. The fist thing we need to do is create the object that we want to follow. For this
recipe, this is THREE.SpotLight :
var sphereGeometry = new
THREE.SphereGeometry(1.5, 20,20);
var matProps = {
Search WWH ::




Custom Search