rpg_el's PositionalSound.js

rpg_el

Veteran
Veteran
Joined
Sep 3, 2020
Messages
64
Reaction score
32
First Language
English
Primarily Uses
RMMZ
rpg_el's PositionalSound.js v1.0.6

Description:
Here is a plugin to play BGS from map events with the according stereo panning/volume fading based on player position. There are new plugin commands you can use in your event page to start playing a BGS from the current event, or another event on the same map by id, and the sound will play from the event until the event is erased, or the player leaves the map, or you use a plugin command to stop it. The sounds need to be restarted every time the player revisits a map if that is desired, similarly to moving an event around all the playback is an "only applicable until map is left" effect. A battle will temporarily mute all events on a map, but sound will resume on its own once the battle ends.

Possible uses: fireplace emitting fire sound, water sounds coming from the location of an actual small pond on a specific spot of the map, ...

Download:
https://wobble.ninja/rpgm/plugins/PositionalSound.js

Note:
If you use this in your game, note your usage by listing "PositionalSound.js by rpg_el/Ellie" in your credits. Please don't redistribute this plugin outside of a game, e.g. as part of a plugin collection, without asking me.

Edit: Usage Guide:

Because it's easy to accidentally just put a sound instruction into a parallel event and have it run each frame (which will lag your game), here is a good performant way of how to set up a sound that works with a pair of events:

Step 1: Add your regular event with any regular interactions as you would like, for example a fire place (please note it's a regular "Action Button" event with text, nothing special):

eventsetup1.png

Step 2: Now add a hidden partner event that auto-launches as soon as the map starts due to being "Parallel", that will make your fireplace emit a sound, and that will self-destruct once the setup work is done:

eventsetup2.png
Please note the "1" for "Event to play BGS from" refers to the fireplace's "ID:001" event id. So the special thing here is the "Erase Event": the partner event (with ID:002 in this case) can erase itself because the sound will play as long as the event it is emitting from exists, which in this case is the fireplace (with ID:001) - so it's no longer needed after starting playback and can go away. This is very performance efficient, because you won't have any parallel event that continues to run in the background the entire time.
 
Last edited:

FrozenNorseman

Shivering
Veteran
Joined
Mar 14, 2018
Messages
90
Reaction score
303
First Language
Danish
Primarily Uses
RMMV
Lovely idea. I can definitely see myself using this to create a lot of atmosphere in my game.

I am having some trouble getting the Play/Update Positional Sound plugin command to trigger as a parallel event when the player enters a map, but I can get the plugin command to work just fine when I make the same event into an action button trigger. Any idea what I am doing wrong?
 

rpg_el

Veteran
Veteran
Joined
Sep 3, 2020
Messages
64
Reaction score
32
First Language
English
Primarily Uses
RMMZ
My first guess would be a bug, the plugin wasn't tested by many yet. It worked fine in my parallel events so far, but who knows.

Do you by any chance have a test project you could link me? (You can also sent me a private message with the link or something)

Edit: just in case it is possibly that: it won't work with MV, only with MZ (I believe there are other plugins for MV though that achieve the same effect)

Edit2: also please note I have no idea if it works fine combined with anything possibly more deeply altering like VisuStella which I don't use. I guess it should work if you put it first in the order, but I can't tell you for certain. In general, anything that hooks into map loading or how basic events are managed could possibly cause a conflict (not that it would necessarily need to, though)
 

FrozenNorseman

Shivering
Veteran
Joined
Mar 14, 2018
Messages
90
Reaction score
303
First Language
Danish
Primarily Uses
RMMV
I've created a small test project. Will be sending you a link shortly.
 

rpg_el

Veteran
Veteran
Joined
Sep 3, 2020
Messages
64
Reaction score
32
First Language
English
Primarily Uses
RMMZ
Okay, so I did find a bug with reissuing the same sound that is already playing which would reset it, which was not intended. I assume you probably made a parallel event reissue the sound each frame, rather than once and then just keeping the event alive (which would be the better way to use it for performance reasons).

I bumped it to v1.0.6 which should hopefully fix the problem.

Playback usage more in-depth: One way to set up a sound for example is to put a parallel event with a playback command, followed by a loop of wait 60 inside. An even better one is to have a parallel event neighboring an action button event with the parallel one setting up a sound to pay from the action button one followed by a self-erase (such that the parallel one ends up instant-erased, but the sound keeps playing from the remaining action button one). If you put a playback command alone into a single parallel event with nothing else after it which I guess you probably did, it'll reissue the sound each frame which should now work but which will cause unnecessary interpreter load.

Edit: I added some screenshots for the usage to the first post now, hopefully that helps
 
Last edited:

FrozenNorseman

Shivering
Veteran
Joined
Mar 14, 2018
Messages
90
Reaction score
303
First Language
Danish
Primarily Uses
RMMV
Fantastic job.
And thank you for adding the usage guide. I'm looking forward to using this in my game.
 

Iqus

Veteran
Veteran
Joined
Oct 17, 2013
Messages
36
Reaction score
27
First Language
Spanish
Primarily Uses
RMMV
Have you considered making it so the source of the sound is a region instead of an event? Otherwise making a river sound the closer you get might require an insane amount of events.
 

rpg_el

Veteran
Veteran
Joined
Sep 3, 2020
Messages
64
Reaction score
32
First Language
English
Primarily Uses
RMMZ
If you increase the distance setting you'll notice roughly one event every roughly third of a screen distance is enough, and MZ has systems in place that reduce lag for events that truly don't run any code (like action button ones that aren't interacted with). I'm also not aware of any "bigger" engine like Unity supporting volumetric sound sources, likely for the same reason: it's possible, but not the simplest to implement, and very trivial to approximate by just placing multiple single point sources as a mapper.

Edit: if you do river sounds with such a chain of point sources, but each with a slightly different pitch, you'll actually also get a much richer sound that slightly morphs in different spots more like a real river would. So it'll also likely get you a better sound than a more uniform volumetric source for the entire thing.

So I'll consider it, but for now I have no intermediate plans to add it. I can see that it would definitely just be very convenient to use, I agree with that. But for now, point sources are just easier for the code and seem in some ways superior too.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Ami
--- Currency ---

Hero: This city cannot accept Gold to buy the items.
Merchant: You can exchange Gold into TC,depending the rate of TC this time.
Hero: Really? Then,i want to exchange 999999999G.
Merchant: Let's see……Wait a second,are you Cheating again?
Hero: Hell No!!! I earn it with myself!!!
There's always a time when you're super excited to create something but you already have no energy left. :I
I think of all the effects in my game, the light passing through fog has got to be my favorite....

...Also I spent all day trying to figure out how I had suddenly messed it up and made it start dropping frames like crazy. So I had all day to look at it... mocking me... with it's previous 60fps reduced to 30fps... At least it's fixed now.
Dalph wrote on slimmmeiske2's profile.
Slimmm, we should team one day and make "Reid in Wonderland" or "Aluxes in boots".

Forum statistics

Threads
103,479
Messages
999,643
Members
135,027
Latest member
Weaversenpai
Top