volume = abs(Player.X - LayoutWidth) / greenBox.width
Grey is layout size(pretend it on my img).
Blue is at the position where it ends, represented by LayoutWidth.
using this formula when the player is at the left side of the greenbox (this is the region the player needs to be inside for the volume to fade) volume will be 1, and when at the right side volume will be 0.
Note, volume will be 0 exactly at the end of the greenbox, where the blue line is. if the player moves further to the right volume will start going up again. so it's important that it is at the end of layout.