Game Development Reference
In-Depth Information
of Body B , the first chain element, you might think that the first chain element is allowed
to rotate only by 45 degrees to either side. But like I said before, angle limits are relative
to Body A ; hence, the more natural initial observation is incorrect.
Instead, the setup shown in Figure 9-7 allows the hook to rotate 135 degrees to either side.
In turn, the other Body B is also allowed to rotate by the same amount. So, from the per-
spective of Body B , the selection handles are simply pointing in the wrong direction. This
is probably going to be confusing for a while, so try to keep in mind that angle limits are
always relative to Body A , and the angle limits are equally applied to Body B but in the op-
posite direction.
Also, take note that Min can never be greater than the Max value, and vice versa. This
may lead to some odd editing behavior where you enter a value and SpriteBuilder changes
it back to make it the same as the other value. Or, if you drag the Min / Max selection
handles, they may suddenly flip to the other side or overlap one another to adhere to the
“Min must be smaller or equal to Max” rule.
Finally, the mysterious Motor . (See Figure 9-6 . ) Only pivot joints currently provide a Mo-
tor property. This is not actually a motor; rather, it is a constraint that applies a constant
rotational force (torque) to the connected bodies. The mysterious Rate property is the de-
sired angular velocity the bodies should take on. Higher values result in more torque. In
order to reverse the direction of the rotation, simply enter a negative value. A motor's
Max force may need to be set to prevent the objects from spinning too fast.
A motor works best if one of the two bodies either has a high density or is a static body,
while the other has a low density and has a circle collision shape (wheel). But, of course,
you are not limited to creating motorized vehicles with wheels. You could also use it to
create a bear trap that snaps open and shut, though any type of motor that needs to be
turned on and off or sped up and slowed down requires writing code.
Connecting the Chain Elements
You are now tasked with adding the six pivot joints to Chain.ccb . Unfortunately, you can't
copy and paste the existing joint, but please do try it in case this feature has been added by
the time you are reading this.
If you can't copy and paste the existing joint, drag and drop six more pivot joints from the
Node Library View onto the stage. Connect the joints one by one to the chain elements
and the ball. Connect the Body A of each joint to the Body B of the previous joint, and
connect Body B to the next element in the chain.
Search WWH ::




Custom Search