   collision detection for a pinball game
  Hello @ll,I have some difficulties with the collision detection for a pinball game. I modelled a pinball table totally OO. I use an interface for each obstacle that I have on the pinball table. This Interface defines among other functions the function isHit( Ball ball ). This function handles the collision detection and the collision response for all different kinds of table-obstacles. There is a vector (java.util.Vector) that stores all the table-obstacles and in each frame, in that I calculate a new ball-position, I iterate over this vector and call isHit() for each table-obstacle. First take a look at my game-loop. With a fix frame-rate I calculate the new-ball-position. In each frame, I calculate the new-ball-position, then I iterate over the described vector and call isHit(). IsHit() does the collision detection and collision response. The collision response “corrects” the current ball position, this means it calculates the exact intersection between an obstacle and the ball and calculates the correct ball position, that the ball should have at the “end” of the frame, although it calculates the new speed-vector for the ball at it’s new position. Table-obstacles describe basic geometric forms like a line, a circle or a circle segment. These basic geometric forms build the game-field. For the collision detection for example of a line (I call it also a boarder) I use “A Sphere-Plane Sweep Test” like described in the article “Simple Intersection Test” from Miguel Gomez on GameDev.net. With this test I get the intersection between a “moving” ball and a plane. Now on my pinball table I have many of these boarder-objects that in some cases touch or penetrate each other.  An example is a corner that consists of 2 boarders. Now if the ball moves to the peak of these two boarders, I get strange collision results. The balls collision is not getting detected. At the edge of the peak the collision detection doesn’t work and so the ball “rolls” inside of the corner, to a position where the ball should not be. I tried to implement something I called a directed-boarder,  when the ball was “rolling” inside of the corner, I detect that it is at a place where it should not be and moved it outside, but this algorithm is very bad, and the result doesn’t look satisfying. Now I’m searching for a collision detection algorithm that can handle my “corner” problem. Or maybe I must implement a new obstacle for corners on my pinball-table. Has anybody experiences with a problem like this, or can tell me some good literature?Regards,Jan 
  This is not exactly about your corner-problem, but you said you are using a "Sphere-Plane Sweep Test" to detect collision between a ball and a line. Now, correct me if I''m wrong, but that sounds like a 3-D algorithm, while pinball is in essence a 2-D game. So I would suggest re-evaluating the way your representing the ball and table for the collision detection and response, and when you move to 2-D everything will be easier and much much faster.shmoove ;  @shmoove: Hello shmoove, The algorithm that I use for collision detection is only a 2-D Algorithm. I used this name for this algorithm because in the article in which I found it this name was used for it. You can see the article under gamedev.net -> article -> "Simple Intersection Tests For Games". Regards,Jan;  OK, nevermind then.Another idea... You say you have an isHit() function that does collision detection and response in one swoop. This might be causing the problem, since you''re doing:Collision detection for object A -> Collision response for object A -> Collision detection for object B -> Collision response for object B.Try separating the collision detection and response code, so that you can first check for all the collisions (with A and B), and just after that calculate the collision response for all the collisions you detected (ie, take into account the combined forces in the collision response).shmoove ;  @shmoove: This could maybe be a solution, but I''m not sure how to handle this. The problem is, that in my collision-detection I do two things, first I detect a collision, the second thing is that I calculate the "exact" collision-position e.g. between the ball and a boarder. After that I execute the collision-response. If I fist "collect" all collisions of the different objects and then I execute a "joint" collision response, I don’t know on which ball-position (which is the "exact" collision-position) I should execute this.Regards,Jan;  Each ball position could be transformed into a force vector (a normal to the ball at that ball position), then in the collision response you add these vectors to create a combined force vector, and do the collision response relative to it. Something like that...shmoove ;  Come to think of it, if it''s a circle-line collision the force would be perpendicular to the line.shmoove ;  @shmoove: "Each ball position could be transformed into a force vector (a normal to the ball at that ball position)" I don''t really understand this part, the rest is ok. In my game loop I always have a current-ball-position and a old-ball-position. The collision is somewhere in between. If in one frame there is more then one collision (2 boarders), I have a problem to calculate the "exact" collision point, maybe there are 2 collision points. Collision-point with the first boarder and the collision-point with the secound boarder. Did I get this right, that you mean I should approximate both collision-points, maybe in the middle of both collision-points, and execute the "combined-collision-response" at this approximated ball position?Jan ;  Not exactly. I mean calculate the effects of both collisions and mix them.May I ask, how are you performing the collision response right now?shmoove ;  @shmoove: When I have a collision detected, I now the exact collision point, the collision-time (normalized time in one frame), the balls-speed-vector, and I now the "collision-tangent" in this point. The tangent describes the bevel at which my ball should get reflected. I know the current-ball-position and the old-ball-position. With this information I can calculate the reflection of the balls-speed-vector at the collision-tangent. And with the collision-time information I can calculate the "new"-ball-position after the reflection and it''s new speed-vector.. that’s roughly how my collision-response works..My problem maybe gets clearer if you take you look at a corner of the pinball-table. If the ball hit''s near a corner, of the table, during one frame sometimes the ball should get reflected twice. It should get reflected i.e. on the right-boarder and on the lower-boarder.. I although discussed this problem with one guy in the physics forum here on GameDev. Maybe you can take look at this thread.. Regards,Jan