ID:151729
 
I'm fishing for ideas on how to setup a system which will produce sound effects from a certain object within view/range/etc, play that sound effect to the player repeatedly, and then constantly update the 3D position and volume based on where that object is in relation to the player. Then when the player is no longer in range, the sound stops playing.

(Efficient ways would be nice. Having objects constantly send out sound effects to everything nearby isn't what I had in mind.)

Any thoughts?
I am sure byond already has a built in something that should do this already.

they have a range thing and all, um, I looked it up, not much i could find, i do however see something called falloff for sound and all, not sure how to use any of it, maybe there might even be a lib out for it, im just not sure, i never used it before.
In response to Dan0971
If you don't know, you could just not answer. :P

I already came up with a way to do this (always open to ideas though), however it doesn't seem to be updated the x, y and z coordinates of the sound that's set to repeat=1, although it will adjust the volume just fine.
In response to Foomer
a bit rude considering all you asked was about how to do it in general, you never said the system didn't work with repeat in your first post, seems to be if it's not working as expected when using repeat, that it may be a bug, because its supposed to work, no matter what, and adjusting the volume...

so...post a bug report...
another way you could do it is to use the current system, don't turn repeat on, and find the length of the video, sleep for that x amount of time, and play it over again, that would probably be the way to make your game not lag.
In response to Dan0971
Dan0971 wrote:
another way you could do it is to use the current system, don't turn repeat on, and find the length of the video, sleep for that x amount of time, and play it over again, that would probably be the way to make your game not lag.

If only that were possible.
In response to Foomer
It's possible, byond may or may not have built in stuff to find time, you could use javascript to find out.

Or, if there is no way for custom sound playing in the game, you could yourself find the time for each built in sound yourself, and sleep X time based on what file it is playing.

To find a general time, you could right click the file, and go to properties, it will tell you there.

The javascript way is quite more tricky though.
I've always managed it through mob/Move(), although there may be better ways.

Basically, the method boils down to keeping a list on the mob that holds all of the sound emitters in range, and updating that list whenever the mob moves. If an emitter becomes out of range of the mob's hearing, it is removed from the list and the sound is stopped. If a new emitter is in range, it is added to the list and sound is started. All other emitters are updated to the new x/y/z distances.

If you up with a large number of emitters, it may be worth placing them into grids, and only checking the grids adjacent to player for new emitters. Also, if you are comparing distances, instead of checking the sqrt(dx*dx+dy*dy) against the emitter's maximum range, check (dx*dx+dy*dy) against the square of the emitter's maximum range (which you can precalculate in it's New() process)

It isn't exactly ideal, as it still results in a lot of loops, but it's probably better than having all emitters poll for nearby listeners.

What did you end up doing, out of curiosity?
In response to DarkCampainger
DarkCampainger wrote:
I've always managed it through mob/Move(), although there may be better ways.

Basically, the method boils down to keeping a list on the mob that holds all of the sound emitters in range, and updating that list whenever the mob moves. If an emitter becomes out of range of the mob's hearing, it is removed from the list and the sound is stopped. If a new emitter is in range, it is added to the list and sound is started. All other emitters are updated to the new x/y/z distances.

I'm thinking of doing something similar to this, incorporating it with my sound system library. Basically anyone using the library would have to manually inform the library of when they want an object to start playing the sound for the player, at which point:

1. It creates a special datum for the sound that keeps track of information like the audible distance, falloff, origin location, etc...

2. The sound system starts a loop that continually checks each special sound datum to adjust its settings and make sure its still within range.

When there are no more sound effects being played because their origins are out of range or were deleted, then the sound system loop will quit.

Its not something I'd really recommend for multiplayer games though.

The problem I'm having though is that the sound coordinates don't seem to want to update while I move around the origin object. I can update the volume based on my position, but I can't seem to change the sound coordinates. I am wondering if its a bug.