playMaker

Author Topic: What is your approach to Audio?  (Read 806 times)

wuannetraam

  • Playmaker Newbie
  • *
  • Posts: 17
What is your approach to Audio?
« on: May 28, 2020, 04:09:56 AM »
How would you all do this?

Short explanation:
I have ambiance sound playing. Now if I go in to a house I want the ambiance sound to fade out. And when I go back outside I want it to fade in again. In the house there is also a guy snoring. Its a 3d sound so when you get closer the sound is louder. As shown in my drawing the sphere for the 3d sound goes outside the house. So when the player walks around the house you hear the guy snoaring.

I've tried playing with trigger zones at the entrance of the house but sometimes it gets a bit buggy when you move to fast to it the sound does the exact opposite.




nuFF3

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 74
  • Are we even real?
    • One Month Studio
Re: What is your approach to Audio?
« Reply #1 on: May 28, 2020, 08:03:20 AM »
I'd set the ambient sounds to a different audiolayer in the builtin mixer, and set the volume based on the context from there.
Maybe control it by triggerboxes, one for inside the house, and one outside the door.
Have the trigger inside the house send info to lower the ambient sounds as soon as its triggered, and same for the one outside the house.
I would probably use 'On Trigger Enter' in the 'Trigger Event' action.
The fading could be as easy as using 'Float Interpolate', or 'Float Add' and 'Float subtract' with a clamp.
If you have trouble with fading in between with 'Float Interpolate', then you need to add some logic that dictates if the value hasn't fully faded to another value, then fade from current to whatever it needs to fade to.

Bear with me here.
Say it takes two seconds to fade from 1 to 0, and in the span of one second the script needs to fade back to 1 again.
It's currently at 0.5, but if the previous logic was to only have it fade from 1 to 0, and from 0 to 1, the volume might suddenly jump from its current value of 0.5 to 0 in order to fade back to 1 again.
You'd need to store the value in a 'current' variable and set it to a 'previous' variable once the trigger is hit.
  • In one state, the variable 'currentValue' is 1, and is fading towards 0, stored as 'previousValue'
  • Trigger is hit
  • 'previousValue' is at 0.5
  • Before a 'Fade to 1' state, have another state that sets the value of 'currentValue' to whatever 'previousValue' was before the trigger
  • In the next state, the variable 'currentValue' is at 0.5 and is fading towards 1
However, using 'Float Interpolate' fades based on time, so going from 0.5 to 1 in two seconds will increment slower than 0 to 1.
Use 'Float Add' and 'Float Subtract' for uniformly incrementing values, and with a clamp.
Then its as simple as:
  • In one state, 'currentValue' is being subtracted from
  • Trigger is hit
  • 'currentValue' is at 0.5
  • In the next state, 'currentValue' is being added to
No need to store the value in a different variable, just add and subtract, with a clamp of course.

wuannetraam

  • Playmaker Newbie
  • *
  • Posts: 17
Re: What is your approach to Audio?
« Reply #2 on: May 31, 2020, 08:09:22 AM »
Thank you for taking the time to respond.
I've fixed it now with Trigger Zones and Animate Float to fade the audio out.
Seems to work great.