Game Development Reference
In-Depth Information
Screenshot of the ballistic demo.
longer to do its work. Likewise, if we are using a higher gravity coefficient in the game,
it will make the ballistic trajectory far too severe: well-aimed projectiles will hit the
ground only a few meters in front of the character. To avoid this we lower the gravity.
For a known change in speed we can work out a “realistic” gravity value using the
s g normal
where g normal is the gravity that you want to simulate. This would be 10 m/s 2 for
most games (which is earth gravity, not the general gravity being used elsewhere in
the simulation, which is typically higher). For our bullet example we have a g bullet
of 0.5 m/s 2 .
g bullet =
The ballistic demo on the CD (shown in figure 4.1) gives you the choice of four
weapons: a pistol, an artillery piece, a fireball, and a laser gun (indicated by name at
the bottom of the screen). When you click the mouse, a new round is fired. The code
that creates a new round and fires it looks like this:
Excerpt from src/demos/ballistic/ballistic.cpp
// Set the properties of the particle.
case PISTOL:
shot->particle.setMass(2.0f); // 2.0kg
shot->particle.setVelocity(0.0f, 0.0f, 35.0f); // 35m/s
shot->particle.setAcceleration(0.0f, -1.0f, 0.0f);
Search Nedrilad ::

Custom Search