SE That Plays Faster The Closer You Get to an Object

So, right now, I have a script that plays an SE or a BGS louder the closer you are to the specified object. What I'd like is an SE that plays, say, a second or two apart when you're really far away from the exit, and plays more and more frequently the closer you are. I'm not really good at proximity stuff in RM so I'm a little oblivious to how this would actually be done, whether it needs a script or not, etc.
Hmm. I have an idea how to go about this. In my project I have an enemy that watches how close you are to it, and attacks when you get too close, with the type of attack changing based on the distance. Took a while to set up. You could use that system, and hook it up to a variable that you use in a script call to wait. Theoretically it'd be something like this in a common event run via parallel process:

Wait 5 frames. (So it doesn't spam it and lag the game.)
*Distance calculation here*
Distance_Variable equals 20 after this, assuming you're ten tiles away (It's about twice the number of tiles between the two objects).
Distance_Variable / 10 (To make it 2, the number of seconds; adjust here accordingly.)
Distance_Variable = Time_Variable
Time_Variable * 60 (This equals the number of frames to wait)
Script Call: "wait($game_variables[0])" (0 being the number for your time variable.
Play SE.
Set all the variables back to zero.
Exit Event Processing (I always do this just to be safe.)

1633656061817.png


Here's my setup for the distance checker, highlighted. I use pixel movement, so I multiply the result by 2 to get a more accurate distance. This is actually a roundabout way of performing the distance formula, since I didn't know how to do it in a script call.

Thoughts?

Edit: Here's a bigger version of the common event. Thought the other one might be too hard to read.

1633656533299.png


Hope that helps.
It works! Had to make some edits so that it doesn't spaz when you get too close to the exit, but other than that, it worked perfectly. Thanks.
No problem! May I ask what kind of edits you made? Might be useful for my system, or anyone who finds this page, for that matter.
Sure! This is my event.
1633712191402.png

Didn't change much, I just the SE to play at a constant rate if time was less than 30 so that it didn't sound like the game broke.
Looks like you're missing the script call to square root the result, but the only reason I did that was to get as accurate a distance as possible. So you probably didn't need it anyway. 😛
Glad it worked out for you!
Yeah, I put that in and got an error, so I just took it out, LOL.
Hi, I found on another site a Script that is very useful for this.
As I don't know if the terms really follow the minimum standard of the community, I'll just give you the name:
Google it:
VXA Dynamic Sound Emitting Events 1.0.5

Or this:

Original thread: https://forums.rpgmakerweb.com/threads/se-that-plays-faster-the-closer-you-get-to-an-object.141093/