How do I verify from server that an ability/skill is possible to happen efficiently?

I want to make ability/skill projectile system, but if I let the server to handle visual effects, I’m afraid that It will be laggy for laggy players… So I decided to let the clients handle the visual effects while the server does verifications to prevent exploiters.

This is the steps:

  1. Client tells the server that the player is using an ability.
  2. Server every client to create its visual effects.
  3. When the projectile hits someone in a client, the client will send “onHit” event to server. (Intendedly, every client will send same “onHit” event.)
  4. After getting an “onHit” event from a client, the server will check if it the “onHit” event is possible to happen using raycast from projectile’s origin to target direction. If the ray hit specific player (based on data the clients gave), then damage the player and don’t accept any same “onHit” event from different client. But, if the ray doesn’t hit that player, don’t do anything (wait until other clients fires “onHit” event that is possible).

But there’s one problem, if the ray is blocked by other person who weren’t there when the projectile passes their position, then the player who are supposed to be hit won’t be detected. This is the visualization of the problem:

My solution is to simulate hitbox of the projectile from server, but simulating on server, especially if there are many projectiles will give too much weight for the server to handle, how do I verify that it is possible to hit player using the ability/skill without giving that much weight to the server?

Thank you.


First of all, great question. The solution to your problem is quite hard, in the sense that there are multiple ways to achieve what you want but all will have different limitations.

In your case, your approach seems quite good. The limitation that you found is true, but it will happen quite rarely (depending on the client’s lag). In general, it will be hard to handle laggy clients anyways when coding bullets.

There is a module that you might want to use that handles bullet “physics” in an interesting way (with segmented raycasts) Making a combat game with ranged weapons? FastCast may be the module for you!.

Just remember, whatever solution you pick you will never be able to handle very laggy clients so you should not try to optimize for that.