[Multiplayer] Synching physics based projectiles

Hello everyone,

I’m currently developing a 2D game and transitioning from single-player to multiplayer using Mirror Networking. I’ve already built a large portion of my game in single-player, and I’m progressively adding multiplayer features.

My issue is related to synchronizing shooting in my game. To give you some context, my shooting system is “physics based”: each projectile is a prefab (a bullet) that has a Rigidbody2D and a Collider, and the projectile is spawned from a ShootPoint attached to the player’s weapon.

In multiplayer mode, here’s what I’m experiencing during tests:

  • When a client fires, it sends a request to the server to spawn the bullet prefab.
  • The server then creates the projectile and sends the information to all clients.
  • However, if the player is moving while shooting, the projectiles appear misaligned from the weapon’s ShootPoint (see attached image).

I suspect this misalignment is due to the latency between the client’s request and the server’s generation of the projectile, especially if the player is moving quickly.

I’m basicaly using : NetworkServer.Spawn(projectileInstance); as a way to create my projectile.
And as you can see as a client, It makes the overall experience very unconfortable to play.

Am I doing something wrong ?

I would also appreciate any advice on how modern games with physics based projectiles (such as Battlefield or Call of Duty, for example) tackle their projectile synchronization.

I’m still relatively new to multiplayer development, so I would greatly appreciate any explanations, advice, or references to tutorials/documentation that could help improve this part of my game.

Thank you in advance for your help!

Best regards

Correct.

You’ll want to create the visual representation of the projectile on the client side instantly. The server would then create the projectile “in the past” by spawning it at the location the player was when the shot was fired, rather than the player’s current server-side position.

When the network object has been spawned, you can then replace the networked projectile with the “fake” one the client instantiated right upon firing. You can also try to interpolate the fake towards the actual over a small period of time. Or a number of other solutions to smooth things out, including keeping the “fake” projectile as is and live with or deal with any inconsistencies this may cause.

The right solutions also largely depends on whether the game is cooperative vs casual competitive vs “seriously” competitive.