I was wondering which approach is the best in Multiplayer games. Here’s the question and the solutions I am thinking of.
How to spawn a projectile in Multiplayer from an auto-fire rifle?
When the player presses the button, I setup a timer for auto-fire on the client. When a function is called from the timer, I create a fake projectile on the client and send the fire event to the server, then the server spawns the real projectile. In this case, if a weapon has rate of fire of 600 RPM; the weapon spawns a projectile in 0.1 seconds which means the RPC function will be called in every 0.1 seconds. It looks like it may cause a bottleneck in the network in my opinion. (There can be more than 1 player.)
When the player presses the button, I setup a timer on the client and call an RPC function to setup another timer on the server. When the functions are called from the timers, I create a fake projectile on the client and a real projectile on the server. In this case, only one calling RPC function will be enough; however, stopping fire might be a problem. When the player releases the button, I need to call an RPC function to tell the server that the player has stopped shooting. If that package arrives lately due to a latency, the player will continue to shoot on the server.
Which one is the best? If there’s any solutions better than these, I would like to hear that.