Game Development Reference
In-Depth Information
Figure 9-1 . Joints in the Node Library View
Tip These joints can also be created in code by using the CCPhysicsJoint
class methods. Even though CCPhysicsJoint exposes eight joint-creation
methods in SpriteBuilder, they are only variations of the three joint types: pivot,
distance, and spring. The only joint type CCPhysicsJoint exposes that is
(currently) not editable in SpriteBuilder is the ratchet joint, a kind of pivot joint
that rotates smoothly in one direction but rotates in discrete angles in the oppos-
ite direction.
Here is a description of the three joint types:
Pivot joint This is also known as a pin, hinge, or revolute joint. The pivot
joint has only one anchor, which is the point the two bodies will rotate
around. Consider that, unlike in reality (that is, with gears), the pivot joint
does not have to be directly on top of either of the two connected bodies in
order to rotate the connected bodies around its anchor.
Distance joint This type of joint keeps two bodies at a fixed distance from
each other, while allowing them to revolve freely around each other. Option-
ally, you can enforce a minimum and maximum distance that the two bodies
must not exceed; otherwise, they are allowed to stretch and contract their
distance to a small degree if a large force is applied.
Spring joint This is a variation of the distance joint in that stretching and
contracting is the desired behavior. You can adjust the rigidity (stiffness) of
the spring as well as how much it springs back and forth (damping).
While three joint types may not sound like much, there's a lot you can do with
them—especially if you consider that you can combine the various joints. Many special-
ized joint types of physics engines are built on these three basic joint types.
The same two bodies can be connected with different kinds of joints, and multiple bodies
can be interconnected with joints. This is usually done to create bodies with a “soft” feel
to them. However, you have to be careful in doing so, because interconnected joints add
constraints that can end up fighting against each other. In the worst case, the object will
behave erratically, folding in on itself or “exploding” and possibly triggering an assertion.
Search WWH ::




Custom Search