• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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