Discuss Scratch

TGSP
Scratcher
27 posts

Inverse Proportionality

How would I go about making an equation such that the closer the object is? Because if I use distance and volume, the closer the object is, the quieter the sound will be, which is obviously undesirable.
Thanks so Much,
TGSP
blossombreeze
Scratcher
500+ posts

Inverse Proportionality

I would suggest trying a script like this:

setvolumeto100-distancetoDesired sprite%

This will make the sound get louder when the sprite comes closer. (You can change the numbers around until it gets louder at the level you want)

Hope that helps!
TGSP
Scratcher
27 posts

Inverse Proportionality

Thanks, I was overthinking it and trying to use inverse proportionality.
-Lite-
Scratcher
500+ posts

Inverse Proportionality

TGSP wrote:

Thanks, I was overthinking it and trying to use inverse proportionality.
v = 100/(sqrt((y1-y2)^2 + (x1-x2)^2)+1)?
It's not that complicated…

Last edited by -Lite- (May 28, 2017 16:01:23)

gtoal
Scratcher
1000+ posts

Inverse Proportionality

TGSP wrote:

How would I go about making an equation such that the closer the object is? Because if I use distance and volume, the closer the object is, the quieter the sound will be, which is obviously undesirable.
Thanks so Much,
TGSP
you want the same formula as used for perspective rendering of say a fencepost - the farther away the fencepost is, the shorter its apparent height. So just substitute volume for height and you should be good.

something like this - obviously you'll have to adapt it to your problem…

definemapworldtoscreenxyztosx,sysetsxto1.55*x+0.5-viewerx*e ^of-0.5*y-viewery*180setsyto0.75*e ^of-0.5*y-viewery*-180
-Lite-
Scratcher
500+ posts

Inverse Proportionality

gtoal wrote:

TGSP wrote:

How would I go about making an equation such that the closer the object is? Because if I use distance and volume, the closer the object is, the quieter the sound will be, which is obviously undesirable.
Thanks so Much,
TGSP
you want the same formula as used for perspective rendering of say a fencepost - the farther away the fencepost is, the shorter its apparent height. So just substitute volume for height and you should be good.

something like this - obviously you'll have to adapt it to your problem…

definemapworldtoscreenxyztosx,sysetsxto1.55*x+0.5-viewerx*e ^of-0.5*y-viewery*180setsyto0.75*e ^of-0.5*y-viewery*-180
I didn't think of it this way, but, doing it logarithmically makes more sense

Powered by DjangoBB