Game Development Reference
In-Depth Information
Natural motion using physics
When you bump into a wall, what happens? If you are a character in Dungeon Maze Adventure from
the previous chapter, absolutely nothing—you just stop moving and that's the end of the story. In real
life, things are much more complicated. A bouncy rubber ball traveling at high speed bounces back at
an angle. Something heavier, such as a rock, falls with a thud. Here's another example: when you step
on a car's accelerator, the car gradually increases in speed and takes a bit of time to slow down after
you hit the brakes. These sorts of physical reactions are part of what makes real-world games such as
tennis and car racing so much fun.
Over the next few pages, you'll take the venerable Lh]uan class from Chapter 8 and modify it a step at
a time to illustrate the following kinds of motion that simulate real-world physics:
Acceleration : Gradually speeding up
Friction : Gradually slowing down
Bouncing : Changing the direction of motion when the object hits the edge of the stage
Gravity : Adding a force that pulls the object to the bottom of the stage
Jumping : One of the most required abilities for video game characters
Applying physics to games is easy to do. Most of the techniques boil down to a simple calculation
that's applied to the rt and ru properties. Although the calculations are simple, it's sometimes far
from obvious how they can be used in a practical way. It's exactly this practical application that you'll
In this topic, most of the physics calculations that you'll apply are based on Euler inte-
gration (its popular name is “easy video game physics”). Video game physics appear
to be absolutely precise in the context of a video game, but are actually only approxi-
mations of the real thing. You'll use game physics because the CPU power required
to process them are far, far less than if you used calculations from a physics text-
book. If you need to do precise physical simulations of the real world, Keith Peters's
ActionScript 3.0 Animation: Making Things Move and AdvanceED ActionScript 3.0
Animation go into detail on this subject.
Setting up the project files
In the chapter source files, you'll find an FLA file called lduoe_o*bh] in a folder called Lduoe_o. You'll
open it as a project:
1. In Flash, select File ° Open .
2. Find the lduoe_o*bh] file in the Chapter 8 Lduoe_o folder. Click the Open button.
3. Select Quick Project in the Project panel's drop-down menu.
4. The lduoe_o project is created. Your stage and the Project panel should now look something
like Figure 9-1.
Search Nedrilad ::

Custom Search