Game Development Reference
In-Depth Information
The other cause of exploding complex physics objects is when the object is partially or
entirely stuck in a static body's collision shape. In this instance, the most likely culprit
will be the border elements, with which the chain and rope segments will currently col-
lide. If you position a chain or rope in the level so that it partially overlaps a border sprite
or even a trigger area, you will notice the chain or rope misbehaving.
You need to edit the affected body's collision categories and masks in order to fix this, and
to allow the chain and ball to swing freely even when placed partially inside a border.
Defining the Collision Categories
Before I start to define collision categories, it really helps to take a moment to consider
the goals for introducing collision categories. In this instance, the primary goal is to pre-
vent the chains and ropes from colliding with triggers and borders. They should still be
able to collide with other chains and ropes, and with the player.
The rest depends—chains and ropes may or may not need to collide with gears and saws.
I'll assume you'll want them to collide with chains and ropes. Since gears and saws are
static bodies, they will not collide with other static bodies anyway—this includes borders
and triggers. Thus, gears and saws need not be in a specific category for now.
Of course, the player must still collide with everything, including chains, ropes, triggers,
and borders. Obviously, the player needs to be included in editing the collision categories
and masks.
Since chains and ropes should behave identically in terms of collisions, it makes sense to
use a single collision category “obstacle” for both. This obstacle collision category also
should be used for future objects whose exact collision behavior is the same, meaning col-
lisions with everything but borders and triggers.
Tip It is important when creating categories to consider only the desired beha-
vior rather than the types of objects. Otherwise, you'll quickly end up creating
too many categories, which will make editing collision behaviors more time
consuming, and you may even run out of categories. Remember that you can't
create more than 32 unique categories. See the paragraph on collision categories
and masks in Chapter 4 .
Search WWH ::




Custom Search