Jump to content
  • Advertisement
Sign in to follow this  
khrismuc

2D Pinball - collision works only 99% of time

This topic is 2595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Hey! Congratulations on your Game, man. 2D physics are fun!
Can you post the source for your collision-handling code?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!