Game Development Reference
In-Depth Information
It's going to be a lot more tedious trying to use identifiers to map out what bod-
ies
should be colliding
. You are likely to end up using a lot more identifiers,
too. Simply because you would have to model collision behavior that is already
working without identifiers.
For instance, in an imaginary shoot 'em up game, you may want to prevent the player's
bullets from colliding with the player and other enemy bullets, but the player bullets
should collide with enemies—and vice versa for enemies and enemy bullets. And, of
course, enemies and players should collide.
Masks
.
If you want to allow bullets to hit each other, all you need to do is change the bullet's
Categories
from
playerBullet
and
enemyBullet
to
player
and
enemy
, re-
spectively. If you want the bullets to be able to hit their owners as well, you simply clear
the
Categories
field for both player and enemy bullets.
The
playerBullet
and
enemyBullet
identifiers exist solely to avoid collisions, these identi-
fiers aren't even used in any other Masks fields in
Table 4-1
. Hence, you can combine
them into a generic
NoCollision
category identifier, reducing the total number of
identifiers used by one.
Tip
It's pretty common and understandable to go with category identifiers that
closely model the types or classes of objects used. If you ever find yourself run-
ning into the 32-identifiers limit, do map out your identifiers and try to find
cases where you can combine category identifiers of multiple types of nodes. I
can almost guarantee there'll be room for reducing the number of identifiers if
you think closely about what the actual collision behavior should be.
Setting up Categories and Masks can get pretty hairy real quick. I strongly re-
commend you draw them on paper or in a diagram application, and draw con-
necting arrows to visually see who is supposed to be colliding with whom. Such
a table or diagram helps you keep track of your collision setup, and it will make
it easier to spot whether you need an additional category, or whether you could
combine two categories into one.
Search WWH ::
Custom Search