Pinball Mechanics
Written by Mattijs van Delden (csg216@cs.rug.nl)
Formatting and minor modifications by Gareth Moore
Pinball Mechanics
The only literature about pinball games was a really old issue of
Sinclair User with a two page article called `How the hell did we design a
pinball game?'. Well, it didn't quite explain that (especially the `hell'
part), only a small bit about a method to model the ball and the sides of
the table and that a good pinball game needs `quite a bit of physics'.
This brings me to the three most important aspects of a pinball game:
- the movement of the ball
- effect of flippers hitting the ball
- playability
The last aspect is important for all games. Quite a lot of Archimedes
games lack this last thing. Really, playability is not only important in
pinball, guys! (sorry to keep hammering on this, but it's true)
Moving the ball
If you don't like physics or geometry, skip this section now! Let's face
it physimaniacs, there is nothing like a good old Newtonian formula, is
there? Basic movement of a stainless steel ball (forget the `silver' thing,
silver is expensive so I don't think it's made out of silver) on a
very smooth surface is just a matter of forces (and almost an ideal system).
Gravity pulls the ball down, so if we put the ball on a tilted table
(get it?), it will accellerate. The magnitude of this accelleration
depends on the angle of the surface. I once played pinball on a real table
with an angle of 45 degrees. I must say, that the game was really fast!
The effect of gravity can be simulated by subtracting a specific number
from the speed of the ball in the vertical direction. This number is larger
for tables that are tilted more. Simple eh? The only tiny problem is
finding a realistic looking value for the number and the game is almost
finished. Stop! Don't start coding now, because there is more to a pinball
game!
At the moment, our ball is effectively moving on an `ideal' surface. This
means that there is no friction. In the real world (i.e. the world that
will crush you after you finished your education) there is always friction,
even with a steel ball on a painted surface. Chance is, that this effect
will be visible and if it is visible, we will have to model it.
This means that when something is not visible, we don't model it, because
it will just be a waste of time. We are not going to model the friction
of the air and the ball, because you won't see it. Back to table friction:
it's a force that always points directly opposite to the speed. The
magnitude of the friction vector depends on the materials of the objects that
move and their speeds. The more speed, the more friction.
Thus, it is possible to model friction by changing the speedvector (making
it smaller) depending on the material that is under the ball and the speed
of the ball itself. Again, a piece of cake.
There is another factor: spin of the ball. At the moment, I'm not modelling
this, but if you think I should AND have a good reason why, say the word.
Now we get to the difficult part: letting the ball bounce around a pinball
table. When the ball `hits' an edge of the table, it has to `bounce' back.
To start with the easy part, there is a nice formula that describes a
point mass bouncing from a wall. You can specify the elasticity of the two
objects to get bouncing objects from a rubber ball to a piece of clay.
The only problem is that the formula is about a point mass. The famous
silver ball is hardly a point mass, I hear you say. Wrong! It is, or to put
it better: we will model it as if it was a point mass. This brings us to
the hitting part.
The Sinclair User article described a method to define the edges of the
table using straight line segments. Curved sections of the table can be
made out of a large number of small segments. The placement of the lines is
something special. We don't place them above the edges of the tables, but
move them one radius of the ball to the inside of the table. This means
that when the point crosses the line segment, the (sprite of the) ball
collides with the (drawn) edge.
Now we have a point moving around a table and crashing into linesegments.
When this happens, the point has to bounce back. Therefore, it is extremely
important to have a reliable algorithm to detect when the point is crossing
a segment. When this goes wrong, the ball will fall right through
the table and out of the screen, destroying your memory (believe me, it
happened quite a few times!) This is the moment where I drop the `we' stuff
for a moment, because, I've got the algorithm and you haven't! It cost me quite
a bit of time and energy to design and implement an absolutely reliable
algorithm. But I did it (thanks go to Wilco Dijkstra for helping me
enormously) and it is worth the blood, sweat and tears.
The table consists of a background (for the human to use) and of a set of
linesegments (for the computer to use). I am using !Draw to draw the
linesegments over the sprite of the background. Bezier curves are used for the
curved parts of the table. These curves are converted into a number of
small straight linesegments (flattened) for use in the program.
Flipping around
This is quite a hard part of any pinball game. With the flippers, you can
aim the ball very accurately at various targets (we are talking about principles
of course) and generally smash the silver thing around the table.
Therefore, the flippers in the game have to be really realistic or the
gameplay will go down the drain. Fortunately, I have my own pinball table at
home, so I can compare the program at each step with the real thing.
The best method is to look at that real thing. If you saw your pinball table
in two and look at the inside, you'll see that the flippers are operated
by a strong relay (an electromagnet). Fork out some tape or glue and if
you hit the right button (it's not too hard, there are just two buttons.
If you can find only one, look at the other side of the table) the flipper
is accellerated. The funny thing is that this accelleration does hardly
depend on the ball being hit or not.
I am currently trying a number of methods of whacking the ball. When I have
found the method that works best (in my humble opinion, of course) I will
add it here.
Levels
Unlike the simple tables that were `hot' in the sixties and seventies,
modern pinball tables have lots of levels. Balls roll around over rails
going everywhere and a second small playfield above or under the normal
playfield is more the rule than an exception. So any decent game must have
these things. Actually, modelling levels is quite easy. Instead of one set
of segments for the playfield, there is a set for each level. A parameter
of the ball is the current level that it is on. This number determines
the set of segments to use. Simple. But there is a small catch: changing the
level of the ball. When the ball rolls up a rail, at some point the level
has to be changed from, say, 0 to 1. When this happens, the normal playfield
set of segments will become inactive which means that the ball will
fall right through any edges of this set. The set for level 1 has to take
over at that point. The point where the ball changes level could be a
line segment. When the ball crosses the segment, the level is changed,
depending on the direction of the ball. Another possibility is to use a box.
When the ball crosses the box, the heat is on.
...this page last updated: 2/5/95...
...back to the top...
|