#### Archived

This topic is now archived and is closed to further replies.

# 2d circle-line collision problem, velocities so fast miss collision....

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

## Recommended Posts

I am using a algorithm gotten from : http://astronomy.swin.edu.au/~pbourke/geometry/sphereline/ to test if a ball in my 2d golf game hits a line (right now just have two lines on the field one vertical and the other horizontal). The collision works well, when the ball runs over the line causing a collision i flash that up , and write out to a log file the values. So I know that the collision is happening more or less correctly, the problem comes in when the ball travels faster in a frame than the collision can test. Since its just a line, there is a problem: We have a line, and a ball flying on the screen, if the ball is going slow enough and at the right angle, the collision happens, if the ball is going to fast at the wrong angle to create the scenario: Frame 1: Ballx, Bally Frame 2: Ballx+Ballxv, Bally+Ballyv Ball is before the line, then due to the xv and yv being high enough the ball is over the line in the next frame, so nowhere does a collision happen, even though the ball graphically moves through the line... im sure this is a common problem, im just not sure how to go about fixing it, anyideas? I have tried this in my sphere line inetersect function calling it with not just the x+offset, y+offset (where offset is to get the center of the ball or circle) but with: x+offset+xv, y+offset+yv and even x+offset-xv, and y+offset-yv just to see if i can get the collision to happen more on time no matter what the velocities are, any ideas what i have to do to get this to work properly every time? Thanks, Shane

##### Share on other sites

Keep track of the ball''s position at the previous update-step (P1) and the position at the current update-step (P2). Then test the line segment P1-P2 against your line. If it intersects then you know the ball has travelled across the line.

My Website: ai-junkie.com | My Book: AI Techniques for Game Programming

• 10
• 18
• 14
• 18
• 15