Skip to main content
GameDev.net gamedev.net
🔒 Locked

2D Pinball - collision works only 99% of time

Started by khrismuc May 13, 2011 at 5:44 PM 0 replies 1.9k views
Original Post
khrismuc
khrismuc
Hey guys,

first time poster here.
I'm usually good at figuring things out myself but I feel I'm wasting time trying to pull this off on my own and would like to hear your thoughts.

I'm trying my hand at coding a Pinball game; I implemented basic circle vs. line collision detection, gravity and dampening.
Here's what I have so far:

CYbmH.png

As you can see, the ball's center is tested against the inflated line, and if a collision is detected within the current frame, a recursion function takes care of handling the rest of the frame movement.
All this works fine as long as the ball is moving fast.
As you can see in the right diagram, I'm subtracting the dampening value from the projection before it is subtracted from the movement vector for the second time; if the result is below 0 I set it to 0 i.e. the ball is supposed to roll along the wall. This does sort of work, however the ball will occasionally move through a wall as soon as it's supposed to roll. I changed 0 to 0.0001 and this improved things a bit, it feels dirty though and surely there's a better way to make sure the physics are handled correctly a 100% of the time.

I suspect the problem is caused by a rounding error on account of the floats not being precise enough to handle the required precision.

If you want to take a look at it: http://dl.dropbox.co...571/Pinball.rar
(tap space to hurl the ball upwards, F9 to restart, Esc to quit)

Thanks in advance for any thoughts and comments.
SuperVGA
SuperVGA
Hey! Congratulations on your Game, man. 2D physics are fun!
Can you post the source for your collision-handling code?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.