0
\$\begingroup\$

the simplicity of Minkowski sums are one of the big reasons capsules are used in collision detection, especially for player models. One of the benefits of this should be the ability to perform collision detection through time, at least with simple primitives.

What I want to try is to collide a bullet (with some speed, represented by a point) and a capsule. A point bullet should also have a simple minkowski representation, and a bullet through time should just be a straight line, a point swept through time. Using this information, we should at least be able to derive the time of impact, which alone should allow for any other collision information we want. Basically similar to something like this: https://blog.hamaluik.ca/posts/swept-aabb-collision-using-minkowski-difference/

What I'm having trouble understanding however, is how to collide with a swept capsule, which itself is a swept sphere. I don't understand how I'm supposed to perform the collision, and I can't find any info online.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

First, we'll do the check in the inertial frame of the bullet. We subtract the bullet's position and velocity from the capsule's position and velocity, and then sweep the capsule from its new relative position over its new relative velocity.

If this swept shape includes the origin, then the bullet hits the capsule. We can approximate that to a fair degree of accuracy by making two triangles out of the starting and ending positions of the centers of the top and bottom ends of the capsule, then doing two "distance from point to triangle" tests.

If the closest the shape gets to the origin is less than the capsule radius (plus the bullet radius, if it has one), then the bullet definitely misses. Otherwise you have a hit.

To find the time of the hit, we can take the shortest distance we got from our two triangle tests, and find the closest point to the origin on that triangle. That will correspond to a point on the center line segment of the capsule at a given moment. The barycentric coordinates of that point on the triangle tells you that time as a fraction of the time step. (The triangle either has two points in the present or one point in the future, or two in the future and one in the present — the barycentric coordinate corresponding to the odd point out is the fraction of the timestep you need to seek to from that point's time)

This time will usually be an over-estimate: the origin is already partly embedded inside the capsule at this moment. But you can compute the time since penetration by firing a ray backward from the origin along the relative velocity at that time & location, and finding where that ray exits the cylinder/spherical cap. That gives you a refined estimate for the moment the bullet first touched. For a capsule that is only translating/yawing, this will be exact. For a capsule that's pitching or yawing, you can test if this point is still inside the capsule at that time, and use binary search to reduce the error below your chosen threshold.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .