Public Group

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

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

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633271
• Total Posts
3011163
• ### Who's Online (See full list)

There are no registered users currently online

×