Game Development Reference
In-Depth Information
Further adding to the confusion is the fact that both a body's category and a body's mask
are considered in a cross-reference test, and only one of the two tests need to be true in or-
der for collision to occur.
If you have two bodies, A and B, one of A's categories must also be in B's mask or one of
B's categories must be in A's mask for both of them to collide. Keep in mind what I said
earlier: an empty field is treated as if all identifiers are set in that field. That means if you
set A's category and mask to ACat but only B's category to BCat , leaving its masks field
empty, the two bodies will still collide because body B's empty mask field matches any
and all categories of body A.
If you expressly want to prevent two bodies A and B from colliding, you will have to fill
in both the Categories and Masks fields for both bodies and ensure that A's category is not
included in B's mask, and B's category is not included in A's mask. Hold your breath,
there's Table 4-1 coming up, which illustrates this.
Table 4-1 . Categories and masks used by an imaginary shoot 'em
game where bullets should not collide with each other and their re-
spective owners
The simplest form of creating two noncolliding bodies A and B would be to set both the
Categories and Masks fields for body A to ACat and both the Categories and
Masks for body B to BCat . The actual strings used in place of ACat and BCat are not rel-
evant; the important part is that each body's category identifiers must not be in the other
body's Masks list, nor should any of the fields be empty.
Tip Because any body can have up to 32 identifiers in both its Categories and
Masks fields, the collision filtering can easily get pretty confusing. It is best to
draw out a chart ahead of time to determine which types of bodies should not
collide with what types of other bodies rather than which ones should collide.
Determining what bodies should not collide requires you to use category identi-
fiers, but not vice versa, because bodies collide by default.
Search WWH ::




Custom Search