   Flipper Physics
  so progress is going moderate on the pinball game I'm trying to make. The last problem I had is now fixed and collisions between static objects and a ball is working nicely. However, a moving flipper (a very fast one for that matter) is now my next problem and I have little idea on how to tackle this accurately.now I'm not trying to be ultra realistic here, just moderately ;)the ball has no angular velocity, spin or any fancy properties to its velocity, its simply: I'm here now, I want to be here next and I'm moving in a straight line to get there.here's a scenario I'm trying to fix: in 1 frame, (or 1 chunk of time), the ball stars at the black circle and is heading toward the grey circle. in the same time frame a flipper moved from the black outline to the grey outline.where do the two meet in time?what is the velocity of the ball after this collision?the only approach I have is this.1. simulation runs2. simulation finds that the ball might intersect the flipper3. collision detection is run.4. pick a time step, integrate both the flipper and the ball from their start positions to their end positions in this single simulation step using this time step.5. detect the point at which these two objects collide.6. resolve collision as static line segment - static circle test.7. collision normal is flippers perpendicular normal at time of collision.8. balls velocity is reflected along this normal as a perfectly elastic collision *for now9. flipper adds velocity to ball based on its rotation speed at time of collision (how to find this?)Does this sound correct to you guys?thanks for any help.   
  My tip is to use an already established (free) physics engine for this unless you want to learn the physics as a part of learning. If you just want to make a game, go for the third party libraries :)But as a tip:Check for intersections on each triangle both before and after the movement, if the sign (direction to the triangle) changes from start to finish you know you have passed through the triangle at some point. React appropriately.;  I'm at a point where changing to a new engine is not feasible. The only other solution is using a mixture. Maybe box2d (flash port) when testing collisions between moving objects. But I would really rather understand this stuff myself.Also, the problem I see a lot is people struggling with engine limitations, setting up joints, limits, continuous collision... There's a thread over in the box2D forums about a flipper setup and one the solutions was to hard code angular velocities and rotation positions for every rotational value the flipper can be in. Too me that is a very hacky unacceptable solution.If I can't crack this soon I'll have no choice but to use another physics engine for dynamics.thanks for the tip :)   ;  How about dividing the collision in time?I mean you can detect, if that "tube" intersects with the arc-thing. If so, divide the time step to say 20 sub-steps. The physics of the situation becomes lot easier (you can simplify things).I hope that helps.   ;  In the situation you have in the picture, if you are doing coarse-grained collision detection and then doing fine-grained collision detection, your coarse-grained collision detection should be firing. Say, if you take the rectangle containing the ball's old and new positions and the rectangle containing the flipper's old and new positions, those two rectangles intersect. So then you want to find if there really is a collision and precisely when it occurs. You can probably solve that analytically without too much trouble but, honestly, it would be easier to just do a binary search.   ;  I have no problem detecting if a collision will occur at some time. The problems I have are this:1. Finding exact time of collision.2. Finding ball velocity after this collision.   ;  I think Box2D handles high-speed tests by making a bounding box that includes both the previous frame and the next frame - if collisions happen between these boxes, it tries those objects again with half the time step, and recurses a few times until either the bounding boxes no longer touch or the margin of error becomes small enough that it's considered a collision.If you want to find out, search the Box2D code for "time of impact" or "TOI" and you'll probably hit the jackpot.   ;  getting closer now, here's a demo where it finds the intersection:instructions:click to advance simulation time.on the second iteration, hold left keyclick againwatch intersection happen.demonow I need to resolve this collision.I'm trying to understand angular velocity because I think I need it here. from WikipediaI think I have the information I need:at the time of collision (0.57 in this case), the angular velocity of the flipper is: t = 0.57w = (flipper angle at t) / tso we now need to find the torque acting on the circle at the time of collision?v = (distance collision is from axis) * wwe now multiply the balls incoming velocity by the torque and reflect that along the collision normal?[Edited by - mr_malee on May 4, 2010 9:17:14 PM];  Jwezorek and I suggested something. Did you consider those (subdividing the collision in time)?   ;Quote:Original post by mr_maleegetting closer now, here's a demo where it finds the intersection:instructions:click to advance simulation time.on the second iteration, hold left keyclick againwatch intersection happen.demonow I need to resolve this collision.I'm trying to understand angular velocity because I think I need it here. from WikipediaI think I have the information I need:at the time of collision (0.57 in this case), the angular velocity of the flipper is: t = 0.57w = (flipper angle at t) / tso we now need to find the torque acting on the circle at the time of collision?v = (distance collision is from axis) * wwe now multiply the balls incoming velocity by the torque and reflect that along the collision normal?Actually searching for the exact time of collision would be cumbersome...You should follow szecs and Jwezorek's advice. It is a lot easier to subdivide your timestep. If your timestep is delta_t, then define dt = delta_t / 20 for example. Considering there's no collision at the initial time to, advance to time t = to + dt. Test if there's a collision. If not advance to t += dt till there's a collision or t equals to + delta_t.The torque is of no use at the time of collision. What you need to compute is the "collision impulse" and add it to each body. IMHO, Baraff's papers and Hecker's ones should be read as an introduction for the simulation of rigid body dynamics. There are among the top hits returned by google when you search for "rigid body dynamics".