Game Development Reference
In-Depth Information
That's much better, isn't it? Some of you might still see
a problem, however, which is now almost the opposite of
the problem you were facing before. depPaopK^fa_p now
won't register a collision if the apple is touching an area of
the cat that isn't covered by the _khheoekj=na] subobject.
Figure 7-25 shows some examples.
But is this really a problem? In many games, it isn't. In
fast-moving games, it can actually look more natural to have
a slight overlap between two objects before a collision is
registered than if the collision detection were too precise.
Here's why:
A slight overlap occurring between two objects gives
a 2D game a very subtle feeling of shallow depth that
will seem very natural to players. The human mind
instinctively tries to impose depth onto flat surfaces,
so overlapping objects will be thought to be occupy-
ing slightly different planes.
When players play a game, the mind creates a kind of
texture for the game that is almost tactile. When peo-
ple talk about the “feel” of a game or a player control
scheme, this is what they mean. Overly precise collision detection can make the texture of the
game feel harsh and rough to the player. A little leniency in collision detection can give your
game a softer, spongier feel to it that might be more enjoyable to play.
Figure 7-25. Even though the apple is
touching the cat, neither registers as
a collision because the apple's bounding
box is not intersecting with the collision-
Area subobject.
Take a good look at the collision detection going on in some of your favorite 2D games, and you'll
notice that you can often touch an enemy just slightly and get away with it without a collision being
registered. I can't count the number of times I've been saved by this “fuzzy” collision detection when
jumping over barrels in Donkey Kong or evading Koopa shells in Super Mario Bros. , and it never
seemed like there was something wrong with the game.
This boils down to very carefully thinking about the collision detection in your game and deciding which
kinds of collisions are important and which aren't. Let's have another look at the cat and apple prob-
lem. Would it really make sense to have the cat pick the apple up if the apple were touching its ears? It
definitely wouldn't, and if it did happen it would certainly look wrong. Is it okay for the apple to overlap
with the cat's stomach a bit and not register a collision? Probably—because as soon as the cat touches
the apple with the part of its body that includes its paws, the collision will occur. This would make sense
to the player. The slight overlap would be accounted for as the shallow depth discussed previously (or
maybe the cat's fur), and the player wouldn't notice there was anything wrong with it.
However, if you tested this and discovered that it actually did look really awkward, you could start
adding more rectangular subobjects in areas of the cat to improve or fine-tune the collision accuracy.
You could name them like this:
_]p*_khheoekj=na][HabpA]n
_]p*_khheoekj=na][NecdpA]n
You could add as many of these additional subobjects as you need. The only drawback is that you'll
have to write more code to check for these collisions. And if you have a huge number of them, they
 
Search Nedrilad ::




Custom Search