3D Game Programming

(C. Jardin) #1
height with position.y. The camera is always right in front since we haven’t yet
set the left-right position with position.x.

It might help to think of the camera being attached to the avatar with an
invisible chain.

Wherever the avatar goes, the camera goes as well.


Pretty cool, right? Well, there is a major problem with this approach. What
happens if the avatar starts cartwheeling or flipping (remember that we’re
using the C and F keys for this)? Try it yourself!

The avatar appears to stay still, but everything else starts spinning! (See
Figure 5, Everything Starts Spinning!, on page 45.)

This is because the camera is stuck on the invisible chain that’s attached to
the avatar. If the avatar spins, the camera spins right along with it. (See Figure
6, The Camera Spinning with the Avatar, on page 45.)

That’s not quite what we want. Instead of locking the camera on the avatar,
what we really want is to lock the camera on the avatar’s position.

In 3D programming there is no easy way to reliably lock something to just
the position of another thing. But all is not lost.

Chapter 4. Project: Moving Avatars • 44


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf