Game Development Reference
In-Depth Information
Chapter
10
Soft-Body Physics
In this chapter, you will change the player character from a rigid object to a soft-body phys-
ics object. A soft body is an object whose predetermined shape can bend and flex under the
forces applied to it. If the body is also trying to relax back into its predetermined shape, it is
often referred to as “jelly” physics—especially if the shape is easily deforming and alto-
gether wobbly. That's the kind of soft body you'll create in this chapter.
Since a deformable body changes its shape, the texture (sprite) used to display the body
needs to be deformed also. A regular CCSprite won't do that, as skewing and scaling the
texture alone won't suffice. So in the second half of this chapter you'll dive into Cocos2D's
rendering API, which is based on OpenGL. You'll use it to wrap all OpenGL commands
for the renderer in such a way that even custom drawing code can be accelerated by bene-
fitting from Cocos2D's internal-rendering optimizations.
Rigid Bodies vs. Soft Bodies
A rigid body has a shape that simply will not budge. The shape remains the same no matter
how much force is applied to the rigid body. The main reasons why this kind of physics is
predominant is that it's a lot easier to program, it can utilize faster algorithms, and the res-
ulting physics simulation produces coherent, reliable results.
The disadvantage of rigid bodies is that it only coarsely simulates real-world physics. As
long as bodies aren't contacting one another, everything works, feels and behaves like in
the real world. But once two rigid bodies collide, their collision response is only a rough
approximation of what would happen in the real world. The absorption of collision force
into heat and dissipation of force due to deformation is approximated with only a single
parameter: elasticity (sometimes called bounciness or restitution ).
In other words, even rigid bodies that are supposed to model light objects such as balloons
or leaves will stack on top of one another as if they were strong, solid bodies.
Search WWH ::




Custom Search