0
\$\begingroup\$

I'm trying to figure out how to do continuous collision with a capsule (which would represent a collision volume for a player for example).

Given how common the capsule is in many game engines, and the fact it is merely a circle swept along a line, I would assume that even just normal collision between it any boxes, triangles/arbitrary facets would be abundant, however, I'm having a hard time finding anything on capsule collision.

Somehow I guess I could figure out the swept volume/object intersection (box + 4 capsule collision detection), and binary search my way down to an approximate collision, but this seems far from ideal, especially given the simple shapes involved. I feel given the shapes I should be able to intersect directly and receive the results. I'm not sure how to figure out "where" something intersected along with a swept series with other methods (like GJK).

For my case, I'm currently focused on just AABB collisions and vertically oriented swept 3D capsules, which I hope to resolve (move capsule appropriately back with AABB collision).

\$\endgroup\$
2
  • \$\begingroup\$ If your capsule is vertical and your boxes axis-aligned, you can reduce this to a circle versus AABB rectangle in 2D. If there's no collision in 2D, you're done. If there is, you might still fit above/underneath in 3D, so in those cases you can take the end of the capsule closest to the box and fire it as a sphere vs AABB test. \$\endgroup\$
    – DMGregory
    Commented Jan 16, 2021 at 13:26
  • 1
    \$\begingroup\$ This is the article I used long ago when starting with collision. Essentially what the author did was translate the player's ellipsoid (or could be a capsule) into a unit sphere (size of 1). The rest of the world gets translated by the same matrix and the collision detection gets simplified to just a line-face intersection test. Basically, you remove the capsule from the equation and would do a line-box intersection test. peroxide.dk/papers/collision/collision.pdf \$\endgroup\$
    – Phaelax z
    Commented Sep 14, 2021 at 15:30

1 Answer 1

1
\$\begingroup\$

There is no one-size fits all answer to help you here, it really depends on how you want your game to feel and what abilities you want your player to have. Starting with a capsule is a great start, from here Ray cast a vector downwards from the capsules feet to test how far the capsule is from an AABB. then if that distance is less than how far the entity would fall on the next frame, you can set a flag that the entity is on top of something and snap it to the ground position returned from the ray cast.

This can be expanded to ray cast out from the feet at 45 degree angles in a ring to test if the player is approaching a slope. If one of these side rings hits an aabb figure out what surface geometry the player is actually hitting with a narrow phase collision with that mesh, then from this mesh you can figure out the normal of the triangle that you actually hit, if this normal is less steep than the max incline you want the player to be able to walk up move the player in the direction they are walking and let the downwards raycast slide them up the mesh.

This is a good start that you can expand upon!

Here is a video trying to convey these concepts farther. Specifically this part of the video https://youtu.be/LTlBElDPDDM?t=1164

\$\endgroup\$

You must log in to answer this question.

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