Let me help you out with the math (put this into a mainLoop function) :

```
local point=getObject("Game.GameCurrentCharacter"):getPoint(VCharacterPosition)
local point2={x=500,y=500} // point where is maximum volume
local distance=math.sqrt(math.pow(math.abs(point.x-point2.x),2)+math.pow(math.abs(point.x-point2.x),2))
local perc = 100*(1-distance/1000) //1000 is the pixels distance where the volume should be 0
setVolume(eMusicVolume,math.max(math.min(perc,100),0))
```

You could also do it only on the horizontal axis, what in my opinion would be more likely to be used.

```
local point=getObject("Game.GameCurrentCharacter"):getPoint(VCharacterPosition)
local point2={x=500,y=500}
local distance=math.abs(point.x-point2.x)
local perc = 100*(1-distance/1000) //1000 is the pixels distance where the volume should be 0
setVolume(eMusicVolume,math.max(math.min(perc,100),0))
```

Keep in mind to reset the music volume once your player leaves the scene. Also if you have a volume setting in your options this would be overwritten. In that case you should copy your global volume to a value and multiply with that in setVolume