Pinball

I’m starting a thread on how to do a pinball machine. As of writing this sentence, I’ve never done it, but I hope that my cunning use of physics and your help can help us figure it out. and I’m starting AAAALLL the way at the beginning… so that beginners can follow this too…

I took a look at the pinball shockwave on the altoids site, I’ve attached a screenshot at the bottom…

One thing that you’ll notice is that it doesnt have any curved surfaces (other than the bumbers, which are circles). One of my original thoughts on pinball is that it would be hard to determine how the ball would follow the path of a curve - you would start getting into calculus then… However, you can get away with regular line and circular bumpers, as they have done with the altoids pinball…

So with calculus out of the way, it’s all a matter of using vectors for the behavior of the ball…

when I get home, I’ll draw some diagrams for these…

Determining the downward acceleration on the ball

how it happens in the real world
the earth’s gravity is 9.8 meters per second squared, downward. if the angle of your table is theta, the acceleration of the ball accross the table is going to be 9.8 * sin (theta)

how it happens in the flash world
just pick a constant… any constant you want, and name that the acceleration…

Basic movement of the ball
In the REAL world
the ball is ALWAYS going to want to go down… gravity ALWAYS acts on on the ball, and in those times that the ball is going up (after hitting a bumper, for example) it’s because the force (and therefore the acceleration) excerted by the bumper is greater than gravity’s force

Force? Gravity? what?
In our case, the terms Force and Gravity are going to be interchangeable. Force is equal to the mass of an object times the acceleration. The only mass we need to know is that of the ball, and it’s always constant. So if Force increases, so will the acceleration. I MAY interchange these terms… and it’s ok…

Anyways, in order to move the ball, we need to know it’s velocity at any time… And we can determine the velocity based on the acceleration and the amount of time that has passed…

so:

v(t) = V(0) + a(t) * t

Note: the equation changed… I orginially had posted
v(t) = v(0) + 1/2 * a * t
but the 1/2 shouldnt be there… I was doing bad calculus

that the velocity is equal to the initial velocity plus one half the acceleration times the time passed…

we can check though, that our units are correct:

v = meters/second
a = meters/(second * second)
t = seconds
1/2 = constant (no units)

so if you multiply acceleration times time, you’ll seconds will cancel out, and you’ll get meters/second, which is the unit for velocity… so it’s correct.

How it happens in the Flash world

TIME DOES NOT EXIST IN FLASH!
… at least, not how we know it…

in the real world, the unit of time is the second, and time infinitely divisible. However, in Flash, the unit of time is the FRAME, and time is not infinitely divisible.

if we look back at the real world equation for velocity, you’ll notice that the velocity at time t is the sum of an initial velocity plus an any velocity “made” by the acceleration in time t. With each second, you’re adding a little bit more velocity to the velocity that the object already has…

Easy example of this. Initial velocity is 3, after one second, acceleration adds 1 unit of velocity, so velocity is now 4. after two seconds, it adds another unit of velocity, so velocity is now 5… get my drift?

We can do this in flash! All you have to do, is add whatever constant (assuming you picked the right one) for acceleration to the initial velocity of your object… and make THAT the velocity…

an example of increasing velocity:


onClipEvent(load){
// set the initial velocity to zero...
this.velocity = 0
// set acceleration
this.acceleration = 3
}

onClipEvent(enterFrame){
// add to the velocity
this.velocity += this.acceleration
}

Why enterFrame? because the frame is our basic unit of time… when you enter a frame, you switched frames, which means time has changed. A change in time makes a change in velocity… (since velocity is a function of time)

if you modify this code to fit a movie in flash, it will do ABSOLUTELY NOTHING!

because now you need to figure out how where to put the ball on the screen…

… coming up… putting the ball on the screen

here’s the screenshot…

Hey that looks pretty cool. I wanna play

hahah cool! A Altoids pinball machine. :trout:

determining the location of the ball
in the real world:
the position of an object is usually called x(t) (a function of time)…
“Why not (x, y)? what ever happened to that?”
x(t) is a vector. Just like velocity and acceleration… a vector has a magnitude and direction. From that we can figure out what the x and y coordinates are… but we’re not going to worry about that yet…

just like velocity is the derivative of acceleration, position is the derivative of velocity. So we can say…

x(t) = x(0) + v(t)*t

the position after time t is equal to the initial position plus one half the velocity after time t, times time. And if we do the unit analysis, we’ll prove that this is right. But I’m not going to get into that…

“but wait… doesnt acceleration affect position too?”
Wow, you’re smart… yes it does. We neglected acceleration in this case… the full equation of position is

x(t) = x(0) + 1/2 * a(t) * t^2

“what’s up with the 1/2?”
that’s from calculus… dont worry about it… it’s just there… it comes from integrating time…

“what happened to velocity?”
Velocity got eaten up by the acceleration… basically. there can only be one of these things: constant velocity, or constant acceleration. in this case there’s constant acceleration, which means the velocity is increasing or decreasing, but not constant…
This, believe it or not, makes velocity irrelevant… (I’ll come up with a better explanation of this…)

NOTE THIS: change in position (because a(t) * t^2 gives a position) that comes from acceleration has a degree of 2…

in the flash world:
alright, so remember that section in which we talked about velocity? well, that doesnt matter when it comes to knowing where to draw the ball on the screen… You thought it did… but it doesnt… I misled you… HAHAHAHA!

why did I mislead you? Because if I just give you the equation for position, you wouldnt have understood it why it’s that, and how it’s going to relate to flash… plus, velocity is going to be one of the properties we’ll want to know once the ball starts bouncing around…

… so how to determine where to draw?

As long as the acceleration due to gravity is not canceled out (for example, by the floor) the ball is always going to be moving! so each time a frame passes, the ball is going to be drawn somewhere else…

… will finish this after my meeting…

Slow down adn take a step back.

First off… When making a pinball game in flash it’s ging to have to be simple unfortunately. But… I have a few pointers set up in the other thread that might help you out good buddy :slight_smile:

Take it easy… I also can come up with other stuff for you if you guys wnat… I found out that my client was home at sick today so he cancelled til tomorrow.