Lerped variable volume resetting on loop

So i’ve been running into this minor issue that is bothering me for a while now.

My game has a sound indication for how fast the player is going, and it works based on the Physics2 LinearVelocity. There’s nothing wrong with the sound file itself, as it loops seamlessly as intended. The problem is quite simple, actually.

the math i’m using to change the volume of a channel is the following:
(runs every tick): Sets channel 9 sound volume to:

lerp(SoundChannelVolume(9),playerbody.Physics2::LinearVelocity()/10,0.05)

Lerp allows the volume to fade in/out smoothly.


And this is the logic i’m using for it.

However, whenever the timer resets and the sound loops, it appears that the sound lerps from 0 back to the variable volume.
In theory, this is what is happening:


the drop in the loop shouldn’t be a thing.

Any ideas on how to fix or bypass this?

When you play the sound in the second event, you are resetting the volume to 1. Try setting it to the channel’s current volume using SoundChannelVolume(9) instead of 1.

1 Like

Oh, i see it now. Thanks!