Game Development Reference
In-Depth Information
intersection. Although if our collision response is merely a reflection of the velo-
city, we only really need to compute the normal of the plane.
With this reflected velocity, our asteroid collision will look much better, though
it still will seem weird because the asteroids will reflect and continue at the same
speed as before. In reality, when two objects collide there is a coefficient of resti-
tution , or a ratio between the speed after and before a collision:
In an elastic collision ( C R > 1), the relative speed afterward is actually higher than
the relative speed beforehand. On the other hand, an inelastic collision ( C R < 1)
is one where the relative speed becomes lower. In the case of asteroids, we likely
want an inelastic collision, unless they are magical asteroids.
A further consideration is angular dynamics, which are briefly covered at the end
ofthe chapter.But hopefully this section gave yousome idea onhowtoimplement
a more believable collision response.
Optimizing Collisions
All of the collision detection algorithms we covered allow for testing between
pairs of objects to see if they collide. An optimization question that might come up
is what can be done if there is a large number of objects to test against? Suppose
thereare10,000objectsintheworld,andwewanttocheckwhethertheplayercol-
lides with any of them. A naïve solution would perform 10,000 collision checks:
one between the player and each of the objects. That's not terribly efficient, espe-
cially given that the vast majority of the objects are going to be far away.
So what games must do is try to partition the world in some way such that the
player only needs to test against a subset of the objects. One such type of partition-
ing for a 2D game is called a quadtree , because the world is recursively split into
quarters until each node in the tree only references one particular object, as shown
in Figure 7.14 .
Search WWH ::




Custom Search