Sign in to follow this  
mr_malee

Flipper Physics

Recommended Posts

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: flipper problem 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 runs 2. simulation finds that the ball might intersect the flipper 3. 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 now 9. 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
getting closer now, here's a demo where it finds the intersection:

instructions:

click to advance simulation time.
on the second iteration, hold left key
click again
watch intersection happen.

demo

now I need to resolve this collision.

I'm trying to understand angular velocity because I think I need it here. from Wikipedia

I 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.57

w = (flipper angle at t) / t

so we now need to find the torque acting on the circle at the time of collision?

v = (distance collision is from axis) * w

we 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]

Share this post


Link to post
Share on other sites
Quote:
Original post by mr_malee
getting closer now, here's a demo where it finds the intersection:

instructions:

click to advance simulation time.
on the second iteration, hold left key
click again
watch intersection happen.

demo

now I need to resolve this collision.

I'm trying to understand angular velocity because I think I need it here. from Wikipedia

I 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.57

w = (flipper angle at t) / t

so we now need to find the torque acting on the circle at the time of collision?

v = (distance collision is from axis) * w

we 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".

Share this post


Link to post
Share on other sites
yeah thats what I'm doing in the demo I posted, my subdivision amount is 20 and the total time frame is 1 (dt = 1 / 20).

collision impulse brings up some good web pages on google, thanks for that johnstanp http://www.myphysicslab.com/collision.html

I'll try and implement this and get back to you guys tomorrow with an update

Share this post


Link to post
Share on other sites
This might help:

image

I guess the picture explains everything. The velocity of the paddle is simply calculated from the angular velocity of it. It's the simplest thing you can have, and I think it would be good enough. This method assumes, that the paddle has infinite inertia. If you are unsatisfied with the results, I guess you can simply multiply the paddles velocity with a value to decrease it. Just some constant to make it look good.

You have to get the time of the collision of course.
First, half the time-step and check in which half the collision occurs. Then half that sub-timestep, check again. Repeat this a several times, and you will get a pretty precise collision time (dt_s).

You have to calculate new position of the ball too: use dt-dt_s and the new velocity.

Share this post


Link to post
Share on other sites
I know this is not exactly what you are asking but I thought it may help others trying to implement flippers with a physics engine.

http://www.youtube.com/watch?v=OQPfvbbH4tQ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this