I’m creating a sound system using the new Audio API.
When the weapon shoot a sound is played by the server using the new API (Audio Player connected to Audio Emitter via Wire).
What is the problem behind this: Is server is lagged, the sound will be out of sync with the Client when he shoots. (He mouse click → weapon shoot → 150 ms has passed → audio is played).
Can anyone help me think of a way to solve this case?
Quick disclaimer: I haven’t used the new audio APIs, so I may be incorrect.
You can’t really do much about ping on the server side, so your best bet would be to play the sound locally for the player who is shooting it (as opposed to playing it from the server), then play the sound for every other player from the server. For other players, the gun shooting would already be delayed, so the sound should end up being synced up for them.
You should let clients handle shooting by client-to-client replication.
Shooter should have its own sound play when its client thinks it shot and then server should send this action to other clients which will then process their audio.
One step further would be implementing this specifically in the shooting where shooter sends request for shooting, server processes it and then sends the Shooting to other players, where other players process sounds, visuals and it will have seamless effect.