Hello devs! I've searched high and low to find an accurate swept sphere formula without success. I do own Realtime Collision Detection by C Ericson and it didn't help because I can't math.
Here's the code I have (it's in javascript but lang doesn't matter as long as it's vector math). It only sort of works because it doesn't take into account the angle of the sphere's velocity - I don't know how to get the actual time of impact. Please help with code! I'm REALLY bad at math, sorry…
sweepSphereVsCapsule(a, c) {
const info = closestSegmentSegment(a.position, a.projection, c.start, c.end)
const radii = a.radius + c.radius
if (info.dist2 <= radii * radii) {
vec.copy(info.closest2).sub(info.closest1)
info.penetration = radii - vec.getLength() // ←-- this is the problem
info.hit = true
}
return info
}
And here's what the issue is: [broken image link]