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