Hi,
I'm experimenting with opacity change depending on a distance, and would want to do it between couple of ranges, like 1000 an 1100, where at instance of 1000 would give 100 opacity and 1100 would give 0 opacity. So i tied using clamp, and tried some to other ideas, but don't know what would be the easiest solution for that. So if anyone would have a suggestion, I'd appreciate it.
clamp((1100 - distance(x,y,x,y)),0,100)
distance = 1100 > 1100 - 1100 = 0
distance = 1000 > 1100 - 1000 = 100
distance = 2000 > 1100 - 2000 = -900 > clambed on 0
distance = 500 > 1100 - 500 = 600 > clambed on 100
distance = 1050 > 1100 - 1050 = 50
Develop games in your browser. Powerful, performant & highly capable.
For a generic linear interpolation formula you can use lerp(100,0, clamp((distance - distanceForFullOpacity) / (distanceForFullTransparency - distanceForFullOpacity), 0,1)).
Thanks guys.
with this lerp(100,0, clamp((distance - distanceForFullOpacity) / (distanceForFullTransparency - distanceForFullOpacity), 0,1)) after filling it up it didn't work properly, untill I've switched places for the first two numbers ( so from 100,0 to 0,100) and it worked. Thanks!
Oops! Must have inverted some numbers along the way.