Code:
function setDist(&PointA, &PointB, maxDist, maxVal)
{
var tDist;
tDist = vec_dist(PointA, PointB);
tDist = maxDist - clamp(tDist, 0, maxDist);
tDist /= maxDist;
return(tDist * maxVal);
}
PointA &
PontB are the two vectors to check the distance between.
maxDist is the range of distance the function should use for scaling.
maxVal Is the maximum value that will be returned (when distance is close to 0).
returns the end result.
ex:
setDist(my.x, you.x, 100, 25);
when the distance between the my & you entities is less than 100, the function will return a number between 0 (D = 100) and 25 (D = 0).