Graphics Reference
In-Depth Information
Making the camera follow an object
When you are creating games or visualizations with many moving objects, you might
want to have the camera follow an object around. Normally, when you create a cam-
era, it points to a single position and shows you the scene that falls within its field of
view. In this recipe, we'll explain how you can create a camera that can follow any of
your objects around.
Getting ready
This recipe only makes use of core Three.js functions, so there isn't any need to in-
clude external JavaScript libraries in your source code. If you want to see the final
result of this recipe, you can open 03.01-camera-follow-object.html in your
browser, and you'll see something similar to what is shown in the following screen-
shot:
In this example, you can see that the camera is focused on the sphere. As the sphere
moves across the scene, the camera moves around to stay focused on the position
of the sphere.
How to do it...
For this recipe, we only need to take three simple steps:
Search WWH ::




Custom Search