How do I chenge opacity depending on a distance?

Get help using Construct 2

Post » Mon Jun 06, 2016 4:59 pm

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.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Mon Jun 06, 2016 5:15 pm

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Jun 06, 2016 5:26 pm

For a generic linear interpolation formula you can use lerp(100,0, clamp((distance - distanceForFullOpacity) / (distanceForFullTransparency - distanceForFullOpacity), 0,1)).
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Tue Jun 07, 2016 12:29 am

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!
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Tue Jun 07, 2016 1:30 pm

Oops! Must have inverted some numbers along the way. :oops:
B
69
S
28
G
24
Posts: 977
Reputation: 18,739


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, Bootfit, Exabot [Bot], Huemerson, unicornspitfire, Yahoo [Bot] and 1 guest