Swept Capsule-Capsule intersection (3D)

Started by
13 comments, last by Mercenarey 19 years, 4 months ago
I will look into your code in a few days, since Im going away for the weekend.

Starting by testing against infinite line-cylinder sounds like a good idea. I will test it, then I will report back :)
Quote:CalvinI am only polite because I don't know enough foul languageQuote:Original post by superpigI think the reason your rating has dropped so much, Mercenarey, is that you come across as an arrogant asshole.
Advertisement
Let we do things relatively to one capsule, so that capsule is not moving.
So we need to find intersection of capsule with "swept capsule" , as topic says.

Let at time t1 we have capsule with sphere centers placed at A,B, and at time t2 we have capsule with sphere centers placed at C,D . Let capsule radius is r.

To find intersection with swept capsule you need to

1: Check for intersection with capsules AB and CD
2: Check for intersections with capsules AC and BD
3: Check for intersection with polygons ABCD displaced by +-r along it's normal.
(that is, polygons [A+N*r,B+N*r,C+N*r,D+N*r] and [A-N*r,B-N*r,C-N*r,D-N*r] where N is normal)
You can do it in other order, do faster checks first...

By "capsule AB" i mean capsule with sphere centers in A,B , obviously.
Do swept line line collision, where you simply return when the lines are close enough to each other. A capped cylinder is just the volume around a line extending out in all directions from the line a certain distance.

Quote:Original post by pTymN
Do swept line line collision, where you simply return when the lines are close enough to each other. A capped cylinder is just the volume around a line extending out in all directions from the line a certain distance.

Yes, and that's main reason why capsules is a popular thing for intersections and collisions....

Putting all together, it's intersection of capped cylinder with polygon, can be done by finding closest distance between segment and polygon...
I made a simpler solution, and thus I haven't implemented a true capsule collision.

I really only need capsules for upright items (characters in my game world, trees etc.), and therefore I decided to implement that for now, and I will return to the more complex capsule collision when I need it.

There will be a whole other problem with sweep testing capsules if you allow them to turn as well. Each point on the segment will move with different velocities.


So this is what I did:
First I assure that the capsules are upright (axis pointing up in the world). Then I reduce the capsules to 2D circles, and raycast (one circle center is the ray origin, the combined velocity is the delta, the other circle is static and has the combined radius of the circles). I do this to see if we are even in the ballpark of a collision (and if the collision takes place on the x/z plane, the cylinder part, then I already have time t of collision).

If we are in this ballpark, I move the capsules forward to t (in reality I just take a copy of the base point, and move it forward, I know the axis Y-height and the radius, enough to do the Y-test) and do a 1D collision on the Y-axis, to see if the capsules will ever collide on the Y-axis. If not, then I don't have to take further action.
In the Y-axis test, I test if the overlap will occur on the top/bottom parts of the capsule, or it will collide on the middle, cylinder part.
If it will be on the top/bottom parts, I do an ordinary sphere-sphere sweep test between the top/bottom parts of the capsules. If it is on the middle, I already have the information (time t) from the circle-circle test (extracting further information like Point-Of-Intersection and Dividing Plane is easy once you have t).

I tested it realtime, and it seems solid so far.
One word of warning: If you do the 1D Y-axis test, then remember to add the Y-components of the velocities to the overlap test.


I know this is far from what I wanted to discuss originally, but since I don't need more than upright capsules at the moment, this will suffice for now.
The thought of turning capsules with different velocities really turned me off - I will take that fight when its really necessary :).

[Edited by - Mercenarey on December 21, 2004 6:40:21 PM]
Quote:CalvinI am only polite because I don't know enough foul languageQuote:Original post by superpigI think the reason your rating has dropped so much, Mercenarey, is that you come across as an arrogant asshole.

This topic is closed to new replies.

Advertisement