Hitbox Detection, Client or Server?

On all my previous games, i’ve done hitbox detection on the server out of reflex, cause of exploiters etc. But recently i’ve been considering doing it on the client because it’s way more fluid there. I am thinking I could do that if I am able to support it with some server-sided sanity checks but I am not sure.

Where do you do your hitbox detection and why?

5 Likes

Depends-- what is the purpose of the hitbox? What is the flow of your game?

Typically you would want to put bullet-hitboxes on the server?

Hitboxes for things like swords.

Ideally you do both. Detect it on the client, and if it hits, send it to the server to validate whether or not it should’ve hit.
On the client, you can make some kind of instant feedback so it feels responsive while the server calculates everything and actually deals the damage.
For example, you could play particle effects or animations on the client whenever you hit an enemy so that it doesn’t feel clunky waiting for the server to tell the client to make those effects. This way you can keep the gameplay feeling smooth while having maximum security.

There are other posts about this on the forums, which I’m sure you can find with some searching - definitely some very helpful stuff. I don’t have anything at hand, but it shouldn’t be hard to find.

17 Likes

sorry for responding too late but how do i display those stuff to other clients without the presence of server?

You’d use both the client and the server, so it’d be ordered like this:

  • Local client clicks to interact / attack
  • Particles and effects are created locally
  • Local client tells the server they tried to interact / attack this target
  • Server validates if this is allowed
  • If it is allowed, tell the other clients to create the particles or visual effects
3 Likes

i need to do FireAllClients if it validates the conditions? if so, thanks1

1 Like

That’s what I’d do! Otherwise people could potentially spam it and cause issues if the action isn’t allowed.

What type of sanity checks would be on the server?

  • Distance between attacking player and target
  • Possibly do a hitbox detection on the server (larger to compensate for player ping etc)
  • If you’re doing guns or something like that, range checks + line of sight checks
  • Cooldown between attacks
  • Health checks, i.e. is the attacking player actually alive, is the target attackable by this player?

Whatever’s most appropriate for your system! I might be missing some obvious ones, but these are what I think of for combat systems.

I’m not sure if I’m just not understanding, but what’s the point of checking on the client if you’re going to recheck on the server again? Is it just so the vfx comes out faster and looks cleaner? (sorry for bumping)

on this problem too, I currently just use getquery on server

My current system is Client to Server which then uses Spatial Query to detect people with hitboxes which then uses a damage module. Is this bad or unoptimized? I also am not sure if I want to move to client hitboxes because wouldn’t the player on the other end being hit see the hitbox being inaccurate or way bigger than it is? And if I do a sanity check on the server with magnitude or something, aren’t server hitboxes delayed or sluggish too?
A plan I have in mind if I want to switch to client hitboxes is using a hitbox detection module that returns all characters hit in a table, and then firing to the server with this table to then loop and damage the table (to reduce server firing).