Creating a rag doll
One of the most popular depictions of characters in physics simulations is the rag doll. The visual look of such characters differs according to detail, but the underlying system is always the same—we just attach several physics bodies to a larger physics body via joints. In this recipe, we will create a rag doll.
Getting ready...
Review the creation of a physics-based activity in the Introduction to the Box2D physics extension recipe, the creation of bodies in the Understanding different body types recipe, and the use of revolute joints and mouse joints in the Working with joints recipe, all found in this chapter.
How to do it...
Refer to the supplemental RagdollActivity
class for the code that we use in this recipe.
How it works...
The first step is to define the variables that represent the multiple bodies that make up our rag doll. Our bodies are the headBody
, which represents the head, the torsoBody
, which represents the torso, the leftUpperarmBody
and leftForearmBody...