Jump to content
  • Advertisement
Sign in to follow this  
Galliard

2D Bounding Circle Collision

This topic is 3736 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

I'm trying to create a 2D platformer with irregular terrain. I have my collision working pretty well, but I'm seeing minor irregularities. What I'm doing is a standard ray to ray intersection that returns the percentage of the move that results in the collision (a number from 0 to 1), offset by the radius of the circle. The problem I'm having is that I'm not sure which point on the circle I should perform the collision test at. I've tried three points so far: 1) Same direction as gravity -This works well for falling and walking, but any horizontal movement causes problems 2) Closest point to the line I'm running the collision test against -This works well for movement nearly orthogonal to the line, but causes problems if the approach is somewhat angled 3) Direction of the velocity -This works quite poorly near the edges of the lines Right now I'm combining all 3 of these and things are working all right. I'm still having some odd behavior at angled connections between lines though. I've also considered doing the move and seeing if there's anything in the bounding circle, but then I'm not quite sure how I'm supposed to figure out how much of that move was valid. Any suggestions would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
The point you want to test is the one that would hit the line segment (why are you talking about rays? A ray is infinite in one direction) first, if there is indeed a collision. That should be, IOW, your option 2. Are you sure you're calculating it correctly? What kinds of "problems" are you having?

This is the point where a tangent to the circle is parallel to the line segment. That, in turn, is the intersection of the perimeter of the circle, with a ray extending from the middle of the circle which is perpendicular to the line segment.

Share this post


Link to post
Share on other sites
The problems I have with #2 occur where one segment ends and the other starts.

Consider a situation where one segment goes up and to the right, and another segment goes up and to the left. These segments then meet at the top, creating a peak.

The object is directly above the peak and moving straight down, but passes right through both segments.

The collision test returns a miss against the first segment because the point I'm testing is to the right of the end of the segment (at the lower right corner of the circle). Similarly, the second segment is missed to the left.

Thanks for the help.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!