Chapter 6. Collision Reactions


Bouncing Off the Walls

Conservation of Momentum and Energy

Applying the Conservation Laws

Points to Remember

This is the chapter in which things really start to come together. You will be applying many ideas you learned from previous chapters. In Chapter 4, "Basic Physics," you learned the concepts and equations needed to move movie clips around the screen. With the added concepts of gravity and friction you were able to add even more realism to a programmed system. In Chapter 5, "Collision Detection," you learned how to detect collisions between many types of objects some moving, some not. The logical next step is to learn the physics and equations involved in making objects (movie clips) react to a collision in a physically realistic way. In this chapter we will look at several useful examples of collision reactions. For a few of them, we'll also learn about (and apply) the laws of conservation of momentum and energy. By the end of this chapter you will be able to program billiard-ball collisions, a box or a ball bouncing off a floor or wall, and even a ball bouncing off an angled line! Suddenly games like pinball, pool, and air hockey won't seem quite as mysterious.

graphics/06fig01.gif

I've divided the collision types we'll cover in this chapter into four loosely connected categories:

  • Object-wall collision reactions. This type of reaction should occur when an object like a circle or a rectangle collides with a wall or a floor.

  • Circle-line collision reactions. This type of reaction occurs when a circle collides with an angled line (for example, in pinball physics).

  • Rectangle-rectangle collision reactions. This type of reaction occurs when two rectangular objects collide straight on (no rotation).

  • Circle-circle collision reactions. This type of reaction occurs when two circles (for example, billiard balls) collide at any angle.

We are sticking to these collision reactions for several reasons. The main reason is that most other collision detections do not need a physical reaction. For instance, a point collision with a balloon will most likely result in an animation of a balloon popping, not a programmed reaction. The intersection between two lines is usually used to determine something bigger, like the collision between a ball and a line, so we do not attempt to program any reaction for two lines intersecting.

Another reason why we're only covering a few types of collision detection and reactions is that it's often a good idea to assume that simpler shapes are being used. If your game involves throwing a baseball at a watermelon, then instead of developing specified circle-ellipse collision-detection techniques, it would be faster to assume that the watermelon is a circle (or even a rectangle). The collision detection will be good enough, and the script will run faster than if you were detecting a more complicated shape. This corner-cutting technique is used in almost every major computer game on the market. For instance, in Tomb Raider, the main character is assumed to be a cylinder, rather than a person with complicated proportions. (Betcha didn't know that, did you?) This geometric approximation makes the collision detection much easier without sacrificing much.



Macromedia Flash MX Game Design Demystified(c) The Official Guide to Creating Games with Flash
Macromedia Flash MX Game Design Demystified: The Official Guide to Creating Games with Flash -- First 1st Printing -- CD Included
ISBN: B003HP4RW2
EAN: N/A
Year: 2005
Pages: 163
Authors: Jobe Makar

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