Game Development Reference
In-Depth Information
2. Save the I]ej[Lh]ucnkqj`*]o file and test the project. Try moving the lh]uan object through
the wall. The wall blocks its movement, and there's no gap between the objects. Figure 7-37
shows an example.
Figure 7-37. Axis-based collision detections allow for knife-
edge precision.
Pushing objects
Surprise! I have one more little trick up my sleeve. Do the following:
1. Change the ?khheoekj*^hk_g method call in the I]ej[Lh]ucnkqj`*]o file so it looks as it does
here (the only difference is that the order of the object names has been reversed):
?khheoekj*^hk_g$ s]hh ( lh]uan %7
2. Save the I]ej[Lh]ucnkqj`*]o file and test the project. Move the lh]uan object to the wall.
You can push the wall around the stage!
How is this possible? By changing the order of the arguments, the effect of the code is on the s]hh
object, not the lh]uan object. The only difference is that because the lh]uan object is moving, the
s]hh object has to continuously reposition itself in front of the direction the lh]uan object is trav-
eling in to prevent the two objects from overlapping. (You can find this complete code in the file
I]ej[Lh]ucnkqj`[5*]o.)
Taking a closer look at the Collision.block method
If you are just happy that the new code works and aren't really too worried about the fine details,
feel free to skip to the next chapter. The main thing is that you have a great little tool you can use
in any of your games. If you now have a general idea of how axis-based collision detection works,
why you might need to use it, and how to use a static method with parameters in a custom class, that's all
you need to know. Like I]pd*n]j`ki, it's a utility that you can use whenever you want to, and you
don't need to know how it works.
 
Search Nedrilad ::




Custom Search