Game Development Reference
In-Depth Information
Caution The more rigid a constraint is, the more likely or severe physics
glitches can be. Imagine a soft rubber band and a metal spring connecting two
bodies—for instance, two buckets filled with water. The soft rubber band hardly
pulls the two objects together when pulled, because there is very little force ap-
plied to the bodies even if the band is stretched out by twice its original length.
A metal spring, on the other hand, requires a large amount of force to extend it
even by just a little bit. If you let go of the metal spring, its reaction will be
much more violent than the rubber band stretched by the same distance.
A constraint means that the physics engine is applying forces to the bodies of the joint in
an attempt to keep the bodies positioned within the limits defined by the joint constraints,
rather than just changing their positions. This has the effect that joints may never move
bodies to a precise location that satisfies all constraints. This means two bodies connected
with a joint are unlikely to ever come to rest at the exact same relative positions they ori-
ginally had when you designed them in SpriteBuilder.
Joints can also be used as a means of moving objects through the world. Just entertain the
following thought: Thus far, the game world scrolls by keeping the player centered. What
if you add another invisible node with a physics body and connect that body with a soft
spring joint to the player. Then let the camera follow the invisible node. The camera will
then smoothly accelerate and decelerate depending on the player's movement. If you want
the camera to look ahead rather than lag behind, you could reverse the setup by moving
the invisible node that drags the player behind.
Types of Joints
In SpriteBuilder, three different joint types are available from the Node Library View as
shown in Figure 9-1 .
Search WWH ::




Custom Search