Game Development Reference
F IGURE 8.1
Screenshot of the bridge demo.
particles are likewise linked together to give the bridge some strength. The cables are
cable constraints descending from a fixed point in space.
On the CD the bridge demo shows this setup in operation. You can move an ob-
ject (representing a character) over the bridge. The collision detector applies contacts
to the nearest particles when the object is above them. Notice the bridge stretch and
conform to the presence of the heavy object. In the demo the constraints are shown
as lines in the simulation.
The collision detector needs some explanation. Because we have only particles in
our simulation, but we want to give the impression of a bridge, it is not the collision
between particles that interests us but the collision between the character and the
planks of the bridge. We will return later in the topic to a more robust way of doing
this. For the purpose of this chapter I have created a custom collision detector.
The detector treats the character as a sphere and checks to see whether it intersects
with any of the planks. A plank is a line segment between one pair of particles. If the
object does intersect, then a contact is generated between the character object and the
nearest of the plank particles. The contact normal is set based on the position of the
object and the line of the plank.
Tilting platforms can use the same theory. Figure 8.2 shows a suitable structure.
On the CD the platform demo shows this in operation: the platform will, by default,
tilt in one direction. A weight can be added to the opposite end, causing it to tilt. The
particles that make up the pivot of the platform have been set with infinite mass to
avoid their moving. If the platform were intended to be mobile, they could be set with
a mass similar to the other particles.
The simulation setup is similar to the bridge demo; you can see the full source
code for both on the CD.
One key limitation of this approach is the lack of friction in our contact model. It
was a deliberate choice to leave out friction at this stage: we'll implement it as part of