The lookAt()
method enables you to make a camera look at a target. In this respect it behaves similarly to the previously discussed target
property. However, besides target
being a property and lookAt()
being a method, there is a difference in how to use them. The target
property needs to be set only once, for instance in the init()
method, whereas lookAt()
requires that you put it in the render method in order to keep being executed after the first frame is rendered. Therefore, to make the camera look at an object assigned to a variable plane
, the following line should be added to the onRenderTick()
method:
camera.lookAt(plane);
The camera will continuously rotate in such a way that its own z-axis is pointing at the origin of the target, as shown in the following illustration:
The lookAt()
method is inherited from the DispayObject3D
class. This means you can tell any do3D to look at any other do3D. So, you can't only tell a camera to look at a 3D...