Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: wuannetraam on May 28, 2020, 04:09:56 AM

Title: What is your approach to Audio?
Post by: wuannetraam 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.



(https://i.imgur.com/zFfqcQk.jpg)
Title: Re: What is your approach to Audio?
Post by: nuFF3 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.
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:
No need to store the value in a different variable, just add and subtract, with a clamp of course.
Title: Re: What is your approach to Audio?
Post by: wuannetraam 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.