Should I simulate projectiles on all clients, or simulate on one and fire to the other clients?

I was adding the finishing touches to my projectile system (previous one was made when I was new to coding), buuut I was wondering if there was any way to optimize the new system, which acts something like this:

  1. I create the projectile on the server with all of the parameters needed, then send this data to each client.
  2. I simulate the physics on every client, and the owner of the projectile sends the server hit data. Non-bouncing projectiles will not check for hit parts on clients who don’t own the projectile.
  3. The server does sanity checks for the enemy’s position and the time the projectile hit, then deals whatever on hit effect the projectile has. If it hits a non-player part and certain parameters are true, then the server deletes the part.

(If an AI owns the projectile it’ll just be simulated on the server)

My question: Would it be better to simulate the projectile on one client— then fire every few frames (or when the projectile bounces) to the server?

The server could relay data like currentPosition/newPosition to all clients so they wouldn’t have to do the math themself, but I’m not sure if this would really change much performance-wise. My only issue with the current system is the possibility of frame drops desyncing the projectiles positions from each client, but this is probably a more minor issue in the grand scheme of things :sob:. I’ve done a few stress tests and I don’t get frame drops, and very little lag with 30 projectiles running. Thanks in advance!

1 Like

The client ideally simulates and renders all projectiles. Collisions are reported to the server if the projectile is owned by that client. If your projectile is meant to interact with the environment via the physics engine (e.g. actual bouncing) then the server would simulate a non-rendered projectile for better sanity-checking

1 Like

That would mean each client should do the math for the projectile’s next position right? That’s pretty reassuring to hear honestly, although I do wonder if there would be any reason to keep other client’s projectile position as close to the original client’s as possible

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.