Facepunch / sbox-issues

162 stars 11 forks source link

Audio Tags #5003

Open Gmod4phun opened 4 months ago

Gmod4phun commented 4 months ago

For?

S&Box

What can't you do?

I can't exclude specific sounds from being heard by specific clients (players, cameras if you will) in a nice manner.

Like collisions and rendering can be influenced by tags, the same would be really useful to have for audio, by being able to set tags for SoundHandle objects, and audio include/exclude tags on the Camera or Listener component.

How would you like it to work?

Being able to set tags for SoundHandle objects, with a default set of tags copied from the GameObject/Component that created the sound.

For example: A prop collides, plays and impact sound, so the created SoundHandle would inherit the tags of the GameObject which played the sound. An animation event causes a sound to be emitted, so it inherits the tags from the animated object. Basically anytime a sound is created by something, the created SoundHandle should inherit the tags of the GameObject/Component that caused the sound to play.

In case a sound is played from a context where there is no GameObject that initiated the sound emission (manually using Sound.Play), the created SoundHandle will have no tags, but we would be able to set our own on it.

From my knowledge, audio is being heard from the Camera's position, if there is no dedicated Listener component. So the listener tags could be either implemented on the camera or the listener component. This would make it really easy to make sure certain sounds can only be heard under specific conditions, like an ultrasonic whistle, which can be heard by certain animals but not humans, robots/remote controlled probes with microphones that catch certain sounds/frequencies, or having groups of players near each other while some of them can't hear certain sounds because of being injured/other reasons.

What have you tried?

Currently I'm using a GameObjectSystem that handles existing SoundHandle objects, which I have to add to a global list upon creation, and I am setting the handle's Volume to 0 or 1, depending on whether a client should hear it or not.

The limitation of my current system is that it does not currently work for sounds that I don't create through code myself.

Additional context

I like to think this is not overly complicated, and it would give us more control over what a client is able to hear.

garrynewman commented 4 months ago

This could be useful yeah