We briefly introduced springs in Chapter 16, Springs and Joints. We saw how we can use springs to create soft bodies like cloth. In this section, we will explore other uses of springs.
If we know the collision point, depth, and normal, we can use springs to resolve the collision. This method works by placing a temporary spring at the point of contact that will push objects apart in the direction of the contact normal. The spring should exert just enough force to push the two bodies apart.
The force that the spring exerts on the rigid bodies is called a penalty force. Due to this terminology, using springs to resolve collisions is often called penalty based collision resolution; the following image demonstrates this:
While this method can be used to create stable physics, finding the right k value for the springs often becomes a guessing game. Using the wrong k value can lead to excessive jitter and bouncy objects. Due to the difficulty in finding the right k value, penalty springs are rarely used in modern physics engines.
We created cloth using springs, and we can create other soft bodies using springs as well. For example, let's explore how we can use the same spring systems we used to build cloth to create a soft body cube. We start with eight points and the structural springs between them:
Next, we need to add shear springs to keep the object from collapsing. These springs look like an x on each face. The shear springs tend to keep the object somewhat rigid:
Finally, we need to add bend springs to keep the cube from folding over in its self. These bend springs look like x that cuts the cube diagonally in half:
With this configuration, eight particles are connected by twenty eight springs. This creates a soft body cube. If the springs are rigid, the cube acts like a rigid body. If the springs are loose, the cube acts like jello. We can use the same three spring systems to make other shapes, such as pyramids, into soft bodies.