4 ms·
My collision code is in Rust, actually. Pretty funny. Capsule-plane collisions are pretty simple, simple enough that I can outline here. The first thing you wa
by webkike 10y ago
My collision code is in Rust, actually. Pretty funny.
Capsule-plane collisions are pretty simple, simple enough that I can outline here. The first thing you want to do is find the sphere on the capsule to perform the test on, call this time t_X. Create a line from the segment (starts at t_0, ends at t_1) bounding the capsule and determine its intersection point with the plane. If there is no intersection, just set t_x to mean(t_0, t_1), or halfway on the capsule's segment. If there is an intersection, and the time is between t_0 and t_1, set t_x to that time. Otherwise clamp it between t_0 and t_1.
Now you have a sphere and a position (the time t_x on the capsule segment), and you can perform a moving sphere - plane collision.
This algorithm works because the premise - the point on a capsule closest to a plane will always get closer to the plane, unless the capsule is moving away - is sound, as far as I can tell.
- willvarfar 10y agoHad to go revisit my hobby code to work out what my hangup was. It was specifically capsule/triangle collision I got stuck on. I had reasoned that with just capsule triangle I could do a 3D platform game on a mesh. However, I kept getting very wrong bounces off of edges.
- webkike 10y agoMoving capsule triangle collision is much more complicated but certainly doable. I would have to describe that algorithm in a blog post or by email (if you want to know more, feel free to shoot me an email). The basic premise that allows for simple capsule plane collisions, that the closest point on a capsule will always get closer, breaks down when the plane is bounded.
- willvarfar 10y agoPlease do do a nice blog post about it :) And blog about the collision detection in general. Not just for me, for the next hobby coder bumping into this.
- santaclaus 10y agoChrister Ericson and Gino van den Bergen both have solid and pretty accessible books on collision detection. Christer's Real Time Collision Detection, in particular, is really digestible in bits and pieces as needed for various applications (and he provides code for each example which rocks).
- webkike 10y agoReal Time Collision Detection is great, but leaves almost all capsule collisions to intuition. That was fine for me, but probably pretty unsuitable for people who aren't very good at geometric visualization.
- tricolon 10y ago> the point on a capsule closest to a plane will always get closer to the plane, unless the capsule is moving away What if the capsule is spinning like a boomerang while moving toward the plane?
- webkike 10y agoFor real time collision detection it is sufficient to rotate an object after you have applied linear motion and collision. If you want the rotation to be more accurate you have to divide the timestep.