Hello
My question is what do I need to do to hear sounds from other player for example their footsteps when they’re near enough ?
Do I need to send it via @RPC ? Can you give me an example for this ?
Thank you
If you are updating position and rotation and such, you can probably calculate what sounds you need to play locally. Else you can send states (use bytes or something to make it lightweight).
There are two kind of sounds, movement and shooting and sounds like these which are result of other events like walking and shooting can be calculated locally. just add spheres to player foots which emmit sound when colliding to ground like lerps tutorial or any other way you like. For events which are sound specific like specific voices and screming you can send a RPC to notify others that the event is happend and they can play the sound as the result.
To put it in simple words, I am doing it as follows (though I assume it’s roughly what Ashkan_gc has already stated in more details above):
1.) Whenever audio effects can be triggered automatically by game engine physics (such as footsteps, collisions, hits etc.), use colliders (i.e. no RPC necessary at all).
2,) Whenever audio effects are meant to be triggered by specific scripting logic, use scripted RPC calls, submitting state variables to all other clients. use scripts on local clients to play the required audio whenever the state variables are updated.
1.) is always the more performant solution, and it bears almost no risk of asynchronicity between the connected peers.
2.) should only be used where necessary (depending on your game design)
Hope that’s understandable.