Topic: Pinball game: Collision of a ball with a pinball paddle Pages that link to <a href="https://ozoneasylum.com/backlink?for=30777" title="Pages that link to Topic: Pinball game: Collision of a ball with a pinball paddle" rel="nofollow" >Topic: Pinball game: Collision of a ball with a pinball paddle\

 
Author Thread
racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 01-19-2009 00:16 Edit Quote

I'm lost. I understand how collision is checked with two circles but I need someone to help me with psuedo code to develop the code to check collisions with paddles in a pinball game I want to make.

First off, I found this script here
http://wd-testnet.world-direct.at/mozilla/dhtml/funo/pinballtest/pinball2textAlignCenter.htm
and modified it while learning how it worked. I'm trying to learn javascript by picking apart free resources I find on the web. I needed to learn how to use soundmanager and this script was begging for sounds. Teethgrinder has an image rotate script that I modified while picking apart and got some flippers. I have almost everything ready but I need to figure out the paddle math.

Is there anyone here who has done this calculation before.? I assure you, I've scoured the internet. I have saved two working examples of balls hitting irregular slopes but I don't want to spend forever trying to sort out the script just to back out the calculations. It's seems easier to ask you pros and **gasp** actually code for myself instead of splicing in some code I cut and pasted from somewhere.
Here's my testing version with sound.
http://h1.ripway.com/tinyscript/pinballRedux.html#
Here's my flipper script
http://h1.ripway.com/tinyscript/canvasPinballFlippers.html
and the next link is flippers drawn with the canvas element but they look strange. Could be the way I'm drawing them.
http://h1.ripway.com/tinyscript/CanvasPinballFlipperDrawingTest.html

finally, for testing purposes, here's an ozone pinball script with some flippers. I screwed up the script a little, but shingebas wrote this. it's the perpetual pinball script. I made it work for canvas and then added the flippers. I think I was trying to resize the playing field and then I was going to resize the ball, but it might be easier to resize the paddles smaller if anyone is actually interested in this and wnts to help. I've seriously hit a dead end. I don't know where to find out how to do this.

racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 01-19-2009 00:22 Edit Quote

http://h1.ripway.com/tinyscript/CanvasTestpinballgame.html

Sorry, fogot the the last link above.

This is missing the back ground pic. I just didn't get around to putting it in there yet. sorry.

I'm just hoping someone can help me with the math.

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

IP logged posted posted 01-19-2009 23:49 Edit Quote

Check this out:

http://www.kevlindev.com/geometry/2D/intersections/index.htm

You'll probably need only these tho:
http://www.kevlindev.com/geometry/2D/intersections/intersect_circle_circle.svg
http://www.kevlindev.com/geometry/2D/intersections/intersect_circle_polygon.svg

An interesting way to go about it...

Physics are more complex than simply _detecting_ collision but this is a good place to start

But there is an easier way you could take:
http://box2d-js.sourceforge.net/index2.html

racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 01-20-2009 00:46 Edit Quote

Thnx Arthurio. I've seen those before but I really want to create the code.

Here's what I figure I need to calculate for each flipper.
The big arc is obviously the range of the flipper which is the first thing to check
the green line is the face of the flipper which I need to figure out how to calculate at different flipper angles. I know the that calculating the vectors for the ball that the perpendicular from the paddle will be the vector normal and the outgoing vector angle is just the same angle from the normal as the incoming vector angle.

I'm just wondering if this is what an expert would do, or if I should device a better way to check for collision and rebound angle?

Thanks for your help.

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 01-20-2009 01:23 Edit Quote

You could also express the flipper as a distance function of the segment between its two round extremities and compute distance between that segment and the center of the ball.

I never really thought about pinball's physic. The tricky part to me seems to take into account the extreme speed of the flippers when they go up and could pass through the ball between 2 frames. In such case you'd have to interpolate the positions to find the exact moment and point of contact.

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

IP logged posted posted 01-20-2009 02:02 Edit Quote

racerX, unfortunately you need alot more than that. As poi hinted you need to take into consideration that fast moving object may pass through other objects between frames.

racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 01-20-2009 02:41 Edit Quote

poi said:
You could also express the flipper as a distance function of the segment between its two round extremities and compute distance between that segment and the center of the ball.

I never really thought about pinball's physic. The tricky part to me seems to take into account the extreme speed of the flippers when they go up and could pass through the ball between 2 frames. In such case you'd have to interpolate the positions to find the exact moment and point of contact.





Yeah, I was thinking I would need to calculate the plane in which the ball will strike the paddle and then use the paddle angle from that point to determine the normal for the ball. I'll have the vector so ne I get the normal from the intersection of the ball and the paddle.

I'm thinking I'll treat the paddle like a sphere and then check for collisions once a ball enetrs the portion of the sphere
Once the ball is inside the sphere of collision, i can check for the closest point of collision to the flipper face. The flippers appear instantaneous, so i can treat the ball position at the time of flipper trigger as the collision point.

the ? is where the ball is at the time of flipper being triggered.
the blue dashed line is the leading face of the paddle and the leading edge of the ball.
I only need to know the angle form the leading edge of the ball to the center of the paddle rotation to know what angle the paddle will be at when it hits the ball? Does that seem correct?

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 01-20-2009 02:50 Edit Quote

Personally I'd go for expressing the flipper as a distance function to the segment between its two round extremities. Because you must bare in mind that the flipper might very well hit the ball on its way down, in which case it's easier to do this way than having to consider the upper and lower edge of the flipper + the round edge for the collision detection.

Of course it'd help to only compute the collision if the ball is within the disc where the flipper can move. But the ball is also a fast moving object, so you should actually compute the intersection of the segment formed by its current and previous position with the cone formed by the flipper at its previous and current position.

With that you should be able to estimate the moment and location of the impact.

IIRC Ugo Helias had something similar for a snooker simulation or boucing balls simulation.




(Edited by poi on 01-20-2009 02:56)

racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 01-20-2009 03:04 Edit Quote

Personally I'd go for expressing the flipper as a distance function to the segment between its two round extremities.

I'm hitting a math wall... or maybe just that I don't know the term you're using. Can you explain how that works or what a distance function is. I'm good with math, but the terms escape my memory.

what if I made the flippers a series of invisible bumpers? hehehe
It was my first thought. I could move their positions between frames when you flip the flippers.
I'm still very much a noob scripter and could never actually create this pinball game to begin with, but I wanna learn. Thanks for helping me out.

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

IP logged posted posted 01-20-2009 09:42 Edit Quote

Interesting pinball game poc that uses flash and box2d ... http://hotruby.yukoba.jp/test-web/pinball.html you can actually see that the flash box2d isn't so great with speedy objects ... so I'm guessing the js port of it isn't so great either.

It sounds like a really fun thing that you're doing actually ... would you mind if I tinkered with a version of my own? :P

racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 01-20-2009 16:28 Edit Quote

Arthurio said:
It sounds like a really fun thing that you're doing actually ... would you mind if I tinkered with a version of my own? :P

LOL of course!! It's not even my script to begin with.

hey, I put to gether a pic to explain what I think I need to figure out.
Do you guys know the formula form leverage? I forgot it and I can't seem to find anything with google that doesn't have to do with leveraged buyouts (economics).
do you know where a good physics resource is?

Arthurio
Paranoid (IV) Inmate

From: cell 3736
Insane since: Jul 2003

IP logged posted posted 01-20-2009 18:31 Edit Quote

wikipedia is pretty good...

http://en.wikipedia.org/wiki/List_of_basic_physics_topics
http://en.wikipedia.org/wiki/List_of_physics_topics

racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 01-20-2009 21:33 Edit Quote
quote:

Arthurio said:

Interesting pinball game poc that uses flash and box2d ... http://hotruby.yukoba.jp/test-web/pinball.html you can actually see that the flash box2d isn't so great with speedy objects ... so I'm guessing the js port of it isn't so great either.It sounds like a really fun thing that you're doing actually ... would you mind if I tinkered with a version of my own? :P


Hey, I was just reminded of jsaway when I saw that box2d link.

Have you guys seen this? what do you think and have you used it at all?
http://away3d.com/jsaway-3d-graphics-through-javascript
it's a flash javascript thingee. I don't know the term, maybe interface?


flipper update: still working on making sure the math is correct. No code written
LOL

racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 01-21-2009 03:06 Edit Quote

I would like to ask you guys what would be better to test for.


Should I use the green points and the arc made by the outside of the paddle, or could I get away with using the outer points (of the center of the ball) of the range of collision?

Then , how the heck an a test like this be contructed? is there an example you can think of that I might be able to learn from. I'm assuming I need to find points A B and C. I really don't know where to go from there. Any help would be sorely appreciated.

racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 01-21-2009 06:08 Edit Quote

I found this hit test but I have some questions. From looking at similar scripts before, I think float means a non integer variable. Is that correct? I don't have the first clue. Is this the test I need to build or something similar. It looks like it to me, but I really can't be sure.


From this link
http://ubuntu-gamedev.wikispaces.com/2D+Collision+Detection
Circle in Triangle
Using the halfspace methodology gets a little trickier when comparing two areas. This is mainly because the halfspace test can only check a line vs a point, and an area has an infinite number of points that exist inside of it. So in addition to using the ability of the halfspace tests to check whether the area is on a certain side, we must also check how far away from that side it is. The circle is the easiest thing to check against in this way, since it has a constant distance from its center.

code:
bool circleInTriangle2d(float* a, float* b, float* c, float* center, float radius)
 {
 
     // if clockwise, make it counter-clockwise
     if(inLeftHalfspace2d(b,a,c))
     {
         float* temp = a;
         a = b;
         b = temp;
     }
 
     float away[2],awayPos[2];
 
     // The first edge
     if(inLeftHalfspace2d(a,b,center))
     {
         sub_2d_vector(b,a,away);
         quarterLeft2d(away,away);
         add_2d_vector(a,away,awayPos);
         if(inLeftHalfspace2d(awayPos,a,center))
         {
             add_2d_vector(b,away,awayPos);
 
             if(inLeftHalfspace2d(awayPos,b,center))
             {
                sub_2d_vector(center,b,awayPos);
                 return component2d(away,awayPos) > radius;
             }
             return inCircle2d(center,radius,b);
         }
         return inCircle2d(center,radius,a);
     }
 
     // The second edge
     if(inLeftHalfspace2d(b,c,center))
     {
        sub_2d_vector(c,b,away);
         quarterLeft2d(away,away);
         add_2d_vector(b,away,awayPos);
         if(inLeftHalfspace2d(awayPos,b,center))
         {
             add_2d_vector(c,away,awayPos);
             if(inLeftHalfspace2d(awayPos,c,center))
             {
                 sub_2d_vector(center,c,awayPos);
                 return component2d(away,awayPos) > radius;
             }
             return inCircle2d(center,radius,c);
         }
         return inCircle2d(center,radius,b);
     }
 
     // The third edge
     if(inLeftHalfspace2d(c,a,center))
     {
         sub_2d_vector(c,a,away);
         quarterLeft2d(away,away);
        add_2d_vector(c,away,awayPos);
         if(inLeftHalfspace2d(awayPos,c,center))
         {
             add_2d_vector(a,away,awayPos);
             if(inLeftHalfspace2d(awayPos,a,center))
             {
                 sub_2d_vector(center,a,awayPos);
                 return component2d(away,awayPos) > radius;
             }
             return inCircle2d(center,radius,a);
         }
         return inCircle2d(center,radius,c);
     }
 
    // the center is inside the triangle, so the circle is colliding
     return true;
 }

racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 01-21-2009 06:20 Edit Quote

here's a drawing to illustrate the A B and C points I need to modify the code for in blue.

Nosredna
Obsessive-Compulsive (I) Inmate

From:
Insane since: Jun 2008

IP logged posted posted 06-02-2009 05:49 Edit Quote

I helped work on the flippers for 3D Ultra Pinball (the first one). Then I helped later on the powered bumpers, in think on Nascar Pinball. Man, this is a bear of a problem. Especially with multiball. It's fun to watch you work through it.

WebShaman
Lunatic (VI) Mad Scientist

From: The Happy Hunting Grounds...
Insane since: Mar 2001

IP logged posted posted 06-02-2009 13:06 Edit Quote

How do you guys go about doing the "slingshot" part of the flipper-ball interaction?

That seems to boggle my mind.

I used to be a real pinball wizard, and one of the techniques one learns is how to "slingshot" the pinball to various targets (this means sort of delaying the flipper action as the ball rolls a bit down on the flipper, then pressing the button, using the ball's momentum combined with the flipper action to change the normal trajectory of the pinball to reach areas that would not normally be reachable, for example).

The reason for this technique? Because the pinball does not always interact with the flipper at the desired angle or speed necessary to reach a specific target. Thus, one can change it by using this technique, and improve the accuracy (which means more points, more balls, extra games, etc).

WebShaman | The keenest sorrow (and greatest truth) is to recognize ourselves as the sole cause of all our adversities.
- Sophocles

racerX
Nervous Wreck (II) Inmate

From: Portland Oregon
Insane since: Jun 2006

IP logged posted posted 12-04-2009 04:39 Edit Quote

Man, I found this script again after digging trough a myriad of saved javascript goodies. The dir got so unruly I spent two days sorting and deleting stuff. My dog had chewed the power cord and shorted my old computer. Bad DOG!
I'm posting this new link to the pinball game script

The free hosts I used before didn't like when I began testing php scripts. LOL duhhh

http://www.hardwoodfloorspdx.com/misc/javascript/canvas/test/sound/pinballRedux.html

I have it listed under sound because it uses the soundmanager2
I don't know how to contact the person who originally created the pinball script. I simply added free stuff to it so anyone is free to use it I guess. I reread what I wrote above and in response to someone asking about using the script, I think I impied that they could not use it. I meant to say go ahead, since it was not mine to begin with.


I'll update the flipper script when I find it.

coach
Nervous Wreck (II) Inmate

From:
Insane since: May 2011

IP logged posted posted 05-31-2011 11:03 Edit Quote
Edit TP: spam removed


Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu