Game Development Reference
In-Depth Information
Simulation versus Illusion
It
s important to remember that as fast as ActionScript 3 and the
Flash Player are, they still are not powerful enough to run a truly
realistic physics simulation. Some open-source implementations of
simple physics engines have been written, but most have severe
limitations compared to what is possible in software that is written
much closer to the hardware level than Flash. However, this is not
to say that these engines or even the relatively simple code we will
write shortly in this chapter are not effective at conveying the illu-
sion of physical reactions. Indeed, we will see that even a bare
bones implementation of physics can be effective at suspending
disbelief for the purposes of a game.
'
Reality versus Expectations
Another point that some developers get hung up on when trying to
emulate physics in Flash is striving for real-world values and reac-
tions. While this is admirable, it often yields unsatisfactory game-
play. Take, for example, a platform game with multiple levels the
player can move between by jumping and dropping. If you were to
apply the rather harsh realities of the effects of gravity and friction
on moving bodies, the game would become impossibly hard. This
is because a realistic simulation factors out human response time.
It is hard for people to stop themselves from falling over in real life
once the process begins
it would be practically impossible using a
keyboard and mouse. Characters in games have often jumped
farther, run faster, and controlled themselves in mid-air unlike how
real humans would ever be able to do. This is okay; as I mentioned
earlier, it only takes so much to suspend a player
sdisbelief.Part
of achieving effective physics in games is knowing what the player
will expect to happen, rather than simply trying to mimic the world
precisely. We will explore this more through the following
examples.
'
Example: A Top-Down Driving Engine
Modern driving games for computers and consoles employ a lot of
physics. All sorts of aspects such as road conditions, gear ratios,
tire materials, and chassis weights factor into the math behind
these simulations, and the result (depending on the game) is a
fairly accurate representation of real-world physics. For the pur-
poses of most Flash games, however, what we are about to create
will suffice for a very satisfactory driving experience. This example
is divided into two classes: the Vehicle class, which defines the
properties of the car, and the Game class, which handles input and
manipulates the car
'
s position and rotation. There is also an
Search Nedrilad ::




Custom Search