Pinball  The Basics?
I have been looking for some information on creating a pinball style game. I can't seem to find too much in the way of examples and guidance so I thought I would drop you all a line to see if you can help!
The basics of moving a ball and applying gravity to it seem straight forward enough. Of course things start to get tricky when the ball starts hitting bumpers and the like which will add speed and direction to the ball. Similarly, how could you implement the sides of the table which slope at various angles, flippers also provide a bit of a challenge too. I know it has all been done before but I am interested to get any new ideas on the matter.
Incidentally, is this the right forum for this? Moderators feel free to move to the correct place if needed!
The basics of moving a ball and applying gravity to it seem straight forward enough. Of course things start to get tricky when the ball starts hitting bumpers and the like which will add speed and direction to the ball. Similarly, how could you implement the sides of the table which slope at various angles, flippers also provide a bit of a challenge too. I know it has all been done before but I am interested to get any new ideas on the matter.
Incidentally, is this the right forum for this? Moderators feel free to move to the correct place if needed!
You should make an algo for checking if the ball hits a line from any two points, then construct your tabel from several of those.
Here is a way to find distance between a point and a line
http://astronomy.swin.edu.au/~pbourke/ge...pointline/
If the distance > ballradius + linethickness then there is a collision
Here is a way to find distance between a point and a line
http://astronomy.swin.edu.au/~pbourke/ge...pointline/
If the distance > ballradius + linethickness then there is a collision
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
I found a couple of links for you:
http://mysite.verizon.net/~woodrails/phy...ysics.html
http://www.acorngaming.org.uk/index.php...ding/Pinb2
http://mysite.verizon.net/~woodrails/phy...ysics.html
http://www.acorngaming.org.uk/index.php...ding/Pinb2
unknown Wrote:If the distance > ballradius + linethickness then there is a collision
The problem with this method is that it is possible for the ball to cross the line without ever stepping on it. In one frame, the ball is completely behind the line, while in the next frame, the ball is completely on the other side of the line. This would happen if the ball was travelling quickly, and the frame rate was very low (assuming frame rate independent animation).
Andrew Wrote:(assuming frame rate independent animation).
Here's a better way to do frame rate independent animation: http://www.sacredsoftware.net/tutorials/...tion.xhtml
You'll still have the same problem if your ball is moving fast enough, but much more control from the code, and 100% consistent behavior regardless of frame rate.
If you can manage it, accounting for the case where the ball moves completely through a barrier is a good thing to do, but the implementation of such a thing can get horribly complicated. Be prepared for a big math lesson.
 Alex Diener
You could just do, if the balls displacement in this time step is > the minimum line thickness + ball radius, subdivide time.
Or even easier check for line intersection (ballx, bally, ballxpreviousframe, ballypreviousframe) barrer, if there isnt a mindist collision.
Or even easier check for line intersection (ballx, bally, ballxpreviousframe, ballypreviousframe) barrer, if there isnt a mindist collision.
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
unknown Wrote:You could just do, if the balls displacement in this time step is > the minimum line thickness + ball radius, subdivide time.
That would certainly work.
unknown Wrote:Or even easier check for line intersection (ballx, bally, ballxpreviousframe, ballypreviousframe) barrer
This almost works, but you'd still have to somehow account for the case where the center of the ball just passes one of the line's endpoints, but with the added radius, the endpoint would pass through the ball. This is why it's difficult.
unknown Wrote:if there isnt a mindist collision.
A what collision?
Isn't it funny how you think animating a ball bumping around an enclosed space can't be too complicated!! If there is the possibility of the ball going through an object between frames, couldn't you precalculate the following position of the ball at the same time (basically a frame in advance) so you would know?
Quote:This almost works, but you'd still have to somehow account for the case where the center of the ball just passes one of the line's endpoints, but with the added radius, the endpoint would pass through the ball. This is why it's difficult.
Its not so difficult that way, just if the resultant point D from the algorithm for the minimum distance between line AB and point C, does not lie on the line segment AB set it to the closest out of A or B.
That way you are testing for intersection of a circle with a thick line (diameter 2*linethickness) from AB with circles at the endpoint (with radius linethickness).
mindist collision  minimum distance between a point and line < ballradius + linethickness
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
If that made no sense at all run this program,
the length of the blue line is what you would use in collision detection,
the length of the blue line is what you would use in collision detection,
Code:
// <applet code="Mindist.class" width="400" height="400"></applet>
import java.awt.Graphics;
import java.awt.Color;
import java.awt.event.*;
public class Mindist extends java.applet.Applet {
int dragMode;
Vect2D a, b, c;
Vect2D d, e;
public void init() {
a = new Vect2D((int)(Math.random()*400), (int)(Math.random()*400));
b = new Vect2D((int)(Math.random()*400), (int)(Math.random()*400));
c = new Vect2D((int)(Math.random()*400), (int)(Math.random()*400));
addMouseListener(new ML());
addMouseMotionListener(new MML());
}
public void paint(Graphics g) {
// D is the minimum distance from line A  B to point C
// E is the minimum distance from line segment A  B to point C
double u = ((c.xa.x)*(b.xa.x)+(c.ya.y)*(b.ya.y))/(new Vect2D(b.xa.x, b.ya.y).absSqrd());
d = new Vect2D(a.x+u*(b.xa.x), a.y+u*(b.ya.y));
if(u < 0)
u = 0;
else if(u > 1)
u = 1;
e = new Vect2D(a.x+u*(b.xa.x), a.y+u*(b.ya.y));
g.setColor(Color.white);
g.fillRect(0, 0, 400, 400);
g.setColor(Color.black);
g.drawLine((int)a.x, (int)a.y, (int)b.x, (int)b.y);
g.setColor(Color.black);
g.fillOval((int)a.x2, (int)a.y2, 4, 4);
g.fillOval((int)b.x2, (int)b.y2, 4, 4);
g.fillOval((int)c.x2, (int)c.y2, 4, 4);
g.setColor(Color.red);
g.drawLine((int)c.x, (int)c.y, (int)d.x, (int)d.y);
g.setColor(Color.blue);
g.drawLine((int)c.x, (int)c.y, (int)e.x, (int)e.y);
g.drawString("A", (int)a.x+5, (int)a.y+5);
g.drawString("B", (int)b.x+5, (int)b.y+5);
g.drawString("C", (int)c.x+5, (int)c.y+5);
}
class ML extends MouseAdapter {
public void mousePressed(MouseEvent e) {
dragMode = 0;
if((Math.abs(e.getX()a.x) < 5) && (Math.abs(e.getY()a.y) < 5))
dragMode = 1;
else if((Math.abs(e.getX()b.x) < 5) && (Math.abs(e.getY()b.y) < 5))
dragMode = 2;
else if((Math.abs(e.getX()c.x) < 5) && (Math.abs(e.getY()c.y) < 5))
dragMode = 3;
}
}
class MML extends MouseMotionAdapter {
public void mouseDragged(MouseEvent e) {
if(dragMode == 1) {
a.x = e.getX();
a.y = e.getY();
repaint();
}
else if(dragMode == 2) {
b.x = e.getX();
b.y = e.getY();
repaint();
}
else if(dragMode == 3) {
c.x = e.getX();
c.y = e.getY();
repaint();
}
}
}
}
class Vect2D {
double x, y;
public Vect2D(double x, double y) {
this.x = x;
this.y = y;
}
public Vect2D dup() {
return new Vect2D(x, y);
}
public void mult(double n) {
x *= n;
y *= n;
}
public double absSqrd() {
return x*x+y*y;
}
public double dot(Vect2D b) {
return x*b.x+y*b.y;
}
}
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Or you could just use OpenPL, the Open Physics Library. It's a physics simulation API with a style similar to OpenGL or OpenAL... just kidding! It doesn't exist... yet
haha you fooled me!
http://newtondynamics.com is an open source physics library, kinda tricky though havent really got the hang of it yet.. soon though, once ive done all this other stuff.
http://newtondynamics.com is an open source physics library, kinda tricky though havent really got the hang of it yet.. soon though, once ive done all this other stuff.
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Just to add my two cents (I'll admit to not fully reading each of the replies):
I've always wanted to make a pinball game, but I've never fully understood the math behind it. Quite recently, I've come to the understanding that you can replicate basic pinball physics with simple linetoline intersections.
To model a point object bouncing off of a wall: the wall becomes one line, and the points present point plus velocity becomes the second line. If there is a collision, the point is set to the velocity represented by the resulting third line. I was able to create quite realistic physics with this simple model. lineTest.jpg
I actually started working on this problem again when I realized I could not correctly model the physics of the standard "wood board" game. woodBoard.jpg . Using this new linetoline physics model, the game works wonderfully.
Because a pinball can simply be thought of a single point with a radius, the "collision lines" just need to be put at a set distance from the actual geometry, and the look and feel is perfect. Modeling a ball bouncing off of curved walls (a curve can be "tesselated" into several straight lines) is simple enough. My next problem is how to handle the flippers. My current solution is to proceed as normal for collisions against the flipper, with the exception that I rotate the balls original position coordinate around the flippers pivot at the same angle that the flipper has travelled that timestep.
Please excuse me if haven't been so much answering questions as I have been thinking out loud... !
In a nutshell: you can do pinball with linetoline collisions.
I've always wanted to make a pinball game, but I've never fully understood the math behind it. Quite recently, I've come to the understanding that you can replicate basic pinball physics with simple linetoline intersections.
To model a point object bouncing off of a wall: the wall becomes one line, and the points present point plus velocity becomes the second line. If there is a collision, the point is set to the velocity represented by the resulting third line. I was able to create quite realistic physics with this simple model. lineTest.jpg
I actually started working on this problem again when I realized I could not correctly model the physics of the standard "wood board" game. woodBoard.jpg . Using this new linetoline physics model, the game works wonderfully.
Because a pinball can simply be thought of a single point with a radius, the "collision lines" just need to be put at a set distance from the actual geometry, and the look and feel is perfect. Modeling a ball bouncing off of curved walls (a curve can be "tesselated" into several straight lines) is simple enough. My next problem is how to handle the flippers. My current solution is to proceed as normal for collisions against the flipper, with the exception that I rotate the balls original position coordinate around the flippers pivot at the same angle that the flipper has travelled that timestep.
Please excuse me if haven't been so much answering questions as I have been thinking out loud... !
In a nutshell: you can do pinball with linetoline collisions.
mnajera Wrote:(I'll admit to not fully reading each of the replies)Tsk, tsk... You must read or you'll get nailed every time around here.
What you're talking about is already closely mirroring the second link that Andrew put up.
mnajera nice particle effects thing looks really cool,
Similar to what I said too:
Similar to what I said too:
Quote:Or even easier check for line intersection (ballx, bally, ballxpreviousframe, ballypreviousframe)
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Collision detection for pinball game  johncmurphy  0  4,705 
Sep 6, 2009 02:46 PM Last Post: johncmurphy 

OSX basics  LWStrike  4  2,618 
Apr 27, 2006 12:48 PM Last Post: LWStrike 