Game Development Reference
In-Depth Information
If the distance to the target, n , equals 500 m and the muzzle velocity, v m , equals 800 m/
sec, then the equations for t hit and d give:
t hit = 0.625 sec
d = 1.9 m
These results tell you that in order to hit the intended target at that range, you'll need
to aim for a point about 2 m above it.
3D Particle Kinematics
Extending the kinematic property vectors to three dimensions is not very difficult. It
simply involves the addition of one more component to the vector representations
shown in the previous section on 2D kinematics. Introducing k as the unit vector in the
z-direction, you can now write:
s = x i + y j + z k
v = d s /dt = dx/dt i + dy/dt j + dz/dt k
a = d 2 s /dt 2 = d 2 x/dt 2 i + d 2 y/dt 2 j + d 2 z/dt 2 k
Instead of treating two components separately and then superimposing them, you now
treat three components separately and superimpose these. This is best illustrated by an
example.
Suppose that instead of a hunting game, you're now writing a game that involves the
firing of a cannon from, say, a battleship to a target some distance away—for example,
another ship or an inland target like a building. To add complexity to this activity for
your user, you'll want to give her control of several factors that affect the shell's trajectory
—namely, the firing angle of the cannon, both horizontal and vertical angles, and the
muzzle velocity of the shell, which is controlled by the amount of powder packed behind
the shell when it's loaded into the cannon. The situation is set up in Figure 2-3 .
Figure 2-3. A 3D kinematics example problem