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.

Some how 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 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\$
1
  • \$\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 Jan 16 at 13:26
0
\$\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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.