Game Development Reference
In-Depth Information
Working with axis-based collision detection
Axis-based collision detection not only tells you whether two objects are touching but also by
exactly how much they're overlapping. If you know what the overlap is, you can separate them with
knife-edge precision. Axis-based collision detection works in the following way:
First, it finds out how far apart two objects are. Next, it finds out the half-widths (and half-heights) of
those objects. If the combined total of half-widths (or half-heights) is more than the distance between
them, the two objects must be colliding. You can work out exactly by how much the two objects are
overlapping by subtracting their distance from their combined total widths or heights. Figure 7-36
illustrates how this works.
Figure 7-36. Axis-based collision detection
When you know by how much the objects are overlapping, you can then force them apart by the same
amount.
 
Search Nedrilad ::




Custom Search