Efficient collision detection of sphere with wall

by Logan R. Kearsley   Last Updated May 15, 2019 19:13 PM

I'm building a first-person game where up till now the player has been represented as a dimensionless point; this makes collision detection really easy, as I can just cast a ray along their velocity vector, find the distance to the nearest obstacle, and clamp the magnitude of the displacement vector to that maximum distance on every frame.

Unfortunately, though, this runs into occasional glitches where a player can jump through a corner between two walls, especially if there isn't anything on the other side to collide with--if the player is facing exactly into the intersection, then the projected ray passes right through the corner without registering a hit on either adjacent wall.

To fix this, I want to instead model the player as a finite-sized sphere, which cannot fit through floating-point-error-sized gaps. (This will also have the nice side effect of forcing a minimum standoff distance for the camera from the walls, so you can't stick your eyeball right up against the surface and fill the screen with a single texel.)

Now, checking whether or not that sphere currently intersects a wall is easy. However, I find myself stuck on how to check whether the sphere will intersect a wall if translated in a certain direction--and if so, where.

All of my walls are axis-aligned, which I expect should simplify things.

Any tips?

Related Questions

Updated March 26, 2018 18:13 PM

Updated July 31, 2017 21:13 PM

Updated August 12, 2018 14:13 PM

Updated May 22, 2016 09:05 AM