How do video game hit detection algorithms actually work?

HI hiker_peter US 📗 Student 👁 97 ⚑ Report Mathematics

I've been playing a lot of competitive shooters lately and I swear sometimes my shots don't register even though they looked dead on target. I'm curious about the actual math and geometry that games use to figure out if a bullet or melee attack connects with an enemy. Does latency affect this more than I think?

2 answers

★ Best answer

I've definitely had those moments where a shot looks perfect on my screen but doesn't land, and yeah, it's almost always a latency thing. Most games use what's called hitscan or projectile-based detection - hitscan instantly checks if a ray from your gun intersects with an enemy's hitbox (usually a simplified shape like a cylinder or capsule), while projectiles are actual objects that travel and check for collisions each frame. The issue is that your client shows you a slightly different enemy position than what the server sees, since your input takes time to reach the server and the server's state takes time coming back to you, so what looked like a headshot on your screen might've been a miss on the authoritative server. Some games try to compensate with client-side prediction or aim assist, but there's always that inherent delay - it's why competitive shooters often feel different on low-ping versus high-ping servers.

The frustration is real - I've been there watching a headshot sail right through someone's skull. Latency matters way more than most people realize, but it's not just about your ping; the server has to reconcile what you saw on your screen with where the enemy actually was a few frames ago, and that delay creates a gap. Most shooters use either hitscan (instant raycast from your gun) or projectile physics, but both get warped by netcode - the server might've already moved your target by the time your client sends the shot data. What the earlier answer kind of glossed over is that even with hitscan, some games deliberately add client-side prediction or lag compensation that can make hits feel inconsistent if you're peeking around corners or if the server's reconciliation algorithm disagrees with your client about positioning. It's not always a case of pure latency eating your shots; sometimes it's the game's way of deciding whose version of reality "wins" in a split-second situation.

Your answer

Log into answer.