proximity based volume [SOLVED] :)

0 favourites
From the Asset Store
Hand-animated Sprite Base for isometric game/animation development
  • Here's the setup:

    I have a player sprite and an 'emitter' sprite, what I want to happen is when the player gets within a range of say 600 px of the emitter, I want the engine to play and loop an audio file.

    I want the volume of the audio file to increase to a maximum of 0db and to a minimum of -20 dependant on the proximity of the player sprite to the emitter sprite.

    When the player is out of the range of the emitter, I want the engine to stop playing the audio file.

    I can do most of this myself but I can't work out how to set up the variables and limk them with the volume of the audio file and to clamp the min / max range of said audio file.

    Any help will be appriciated.

    Thanks

  • So looking over the manual I think there are two ways you could do this.

    1) Find a custom plugin for audio (if one exists).

    2) Use multiple versions of the same audio track manually set at different volumes using a sound editor. This would require no plugin, but would increase the number of the same audio file you need for your game. (this increasing its size).

  • There's a way of doing it without duplicating audio files or writing a custom plugin for sure, I just don't know quite know how to do it.

    We can control the volume of an audio file via a variable. I just don't know how to link and clamp that variable with the volume properties of an audio file.

  • Oh oh oh yeah, sorry missed it in the manual.

    Are you asking how to set the distance to interact with the Set volume action?

  • I want to compare the distance between two sprites and adjust the volume of an audiofile accordingly and to update every tick.

    So if player is 600 px or greater distance from the emitter i want to stop playing the file.

    If the player is less than 600 px I want to play the file and to have its volume to ramp up incrementally from -20db.

    If the player is within 100 px of the emitter I want the volume to set at 0 db.

  • This post will be helpful to determine the distance between your emitter and sprite:

    scirra.com/forum/how-to-get-the-distance-between-two-sprites_topic45039.html

    Assign the formula to a variable

    Then you can set a condition of when player sprite comes in X distance then set action to change audio set volume.

  • I get that, but doing it this way would not mean a smooth gradient of volume it'd step.

    For example, if player is 599 px away from sprite : set volume to -20

    if player is 589 px away from sprite : set volume to -19.5

    if player is 579 px away from sprite : set volume to -19

    etc

    There has to be an efficent dynamic way of doing this using min / max values set to clamped variables. I just can't work it out.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You need a formula in the set volume action that has a relationship between a decreasing number and a slowly increasing number.

    Hmmm let me chart this and I might be able to grab the needed formula. Give me about two hours or so. I'm at work and about to get off shift.

  • set volume to: -distance(player.x,player.y,emitter.x,emitter.y) / factor + startingCondition

    Factor should be something from 10 to 200, and determines how quickly the sound fades out when you move away. StartingCondition is the volume you want when the player is right on top of the emitter.

    Hope this helps a little.

  • thanks a lot guys this looks good will try it out at lunch

  • sqiddster EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEIIIIII it works! woo! Marvellous thank you

  • Happy to help <img src="smileys/smiley2.gif" border="0" align="middle" />

  • sqiddster

    I wonder if I could poke your brain a bit more.

    How could I use this formulae to say that if the player is out of range of the emitter, stop playing the audio file but if he is within the range of the emitter to start playing it?

    This way I could place several of these emitters in a level and trigger the area sound dynamically without using lots of resource constantly looping the sound in the background even if it is inaudible.

  • Hmm, you might need to play around a bit, but try something like this:

    If distance < threshold, Trigger once

    Play audio looping

    If distance > threshold, Trigger once

    Stop audio

    Something along those lines should work.

  • sqiddster

    Sorry do you mean

    System Compare

    First Value : -distance(playerbase.x,playerbase.y,audioemitterac1.x,audioemitterac1.y) / 80 + -10

    <

    number

    Stop audio

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)