Game Development Reference
F IGURE 6.1
T HE L IMIT OF E LASTICITY
Real springs only behave this way within a range of lengths: this range is called their
“limit of elasticity.” If you continue to extend a metal spring, eventually you will ex-
ceed its elasticity and it will deform. Similarly, if you compress a spring too much, its
coils will touch and further compression is impossible.
We could encode these limits into our force generator to produce a realistic model
of a spring. In the vast majority of cases, however, we don't need this sophistication.
Players will see a spring doing its most springlike thing; they are unlikely to notice
whether it behaves correctly at its limits of elasticity. One exception to this is the
case of springs that cannot compress beyond a certain limit. This is the case with car
suspensions: they hit their “stop.” After being compressed to this point, they no longer
act like springs but rather like a collision between two objects. We will cover this kind
of hard constraint in the next chapter: it can't be easily modeled using a spring.
S PRINGLIKE T HINGS
It's not only a coiled metal spring that can be simulated using equation 6.1: Hook's law
applies to a huge range of natural phenomena. Anything that has an elastic property
will usually have some limit of elasticity in which Hook's law applies.
The applications are limitless. We can implement elastic bungees as springs. We
could simulate the buoyancy of water in the same way, connecting the submerged
object to the nearest point on the surface with an invisible spring. Some developers
even use springs to control the camera as it follows a game character, by applying a
spring from the camera to a point just behind the character (see figure 6.1).
S PRINGLIKE F ORCE G ENERATORS
We will implement four force generators based on spring forces. Although each has
a slightly different way of calculating the current length of the spring, they all use
Hook's law to calculate the resulting force.
This section illustrates a feature of many physics systems. The core processing
engine remains generic, but it is surrounded by helper classes and functions (in this