Collision Detection Methods

Basically, collision detection, or hit testing, is a very simple concept. You want to know if two objects are occupying any part of the same space at the same time. Of course, you may have a lot more than two objects, and you may want to know if any of them are hitting any others. But when you break it down, you need to test each object one at a time against each other object. So, it always comes down to testing one object against another.

As the title of this section indicates, you have a couple of ways of doing collision detection:

  • You can base the test on the actual pixels of each object (movie clip); that is, does the shape of this movie clip overlap the shape of that movie clip? And for that test, are you considering the actual visible pixels that make up the graphics of that movie clip, or are you going to base it on the rectangular bounds of that movie clip? So, this method has several options for how it is applied. This form of collision detection is built into Flash.

  • You can base the test on distance. You get the distance between the two objects and you ask, Is that close enough for them to be colliding ? This is more of a roll your own method of collision detection. You need to calculate the distance and decide when the objects are close enough.

Each method has its uses. Ill cover both in detail in this chapter, and youll get a good chance to see how they are used.

One thing I wont go into in too much detail in this chapter is what to do when you do get a collision. How are two objects supposed to react when they bump into each other? Ill cover that subject in exhaustive detail in Chapter 11, when I talk about conservation of momentum.



Foundation ActionScript. Animation. Making Things Move
Foundation Actionscript 3.0 Animation: Making Things Move!
ISBN: 1590597915
EAN: 2147483647
Year: 2005
Pages: 137
Authors: Keith Peters

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net