Sign in to follow this  
Galliard

2D Bounding Circle Collision

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

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