Legacy GM Object opacity depending on distance from another object

B

BlackyyGMS

Guest
Hello guys, my question is: how do I change opacity of an object (obj_redacted) depending on distance from player (obj_chara). My point is that I want obj_redacted to be fully visible when colliding with it, but slowly less visible when walking away from it.
 
What you need is two things. lerp() and point_distance(). You also need to decide at which distance you should be fully opaque and which distance you should be fully transparent.
Then you do something like this.
Code:
var min_distance=5;
var max_distance=100;
var current_distance=point_distance(x,y,object.x,object.y);
alpha=lerp(1,0,(current_distance-min_distance)/max_distance);
If you aren't familiar with lerp, check out this video (jump to the 8 minute mark for the explanation).
 
Top