• 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 Depending on the distance between the object variables it will be more visible or less visible

Z

Zanget

Guest
How can I calculate the distance between two variables and depending on the distance of this my object is more visible or less visible.
I create a variable and assign it a value

number_one = 5;
number_two = 0;

What I want to do is that depending on the distance of these two variables affect the image_alpha of my object, I want my object to become more visible while number_two is closer to number_one otherwise my object will be less visible. I do not know if I made myself understand correctly, how can I achieve this?
 

jo-thijs

Member
How can I calculate the distance between two variables and depending on the distance of this my object is more visible or less visible.
I create a variable and assign it a value

number_one = 5;
number_two = 0;

What I want to do is that depending on the distance of these two variables affect the image_alpha of my object, I want my object to become more visible while number_two is closer to number_one otherwise my object will be less visible. I do not know if I made myself understand correctly, how can I achieve this?
So you want this:
Code:
image_alpha = f(abs(number_one - number_two));
with f a function from positive real numbers to real numbers in the range [0,1]?

Like this:
Code:
image_alpha = alpha / ( abs(number_one - number_two) + alpha );
for alpha some strictly positive real number that smooths visibility degration as it grows?
 
Z

Zanget

Guest
So you want this:
Code:
image_alpha = f(abs(number_one - number_two));
with f a function from positive real numbers to real numbers in the range [0,1]?

Like this:
Code:
image_alpha = alpha / ( abs(number_one - number_two) + alpha );
for alpha some strictly positive real number that smooths visibility degration as it grows?
jo-thijs Excellent works correctly!!

image_alpha = alpha / (abs (number_one - number_two) + alpha);

Now I have another question, how can I do the opposite effect? that the closer this number_one of number_two the object is more visible, otherwise it will be less visible, excuse me I'm still a noob in game maker
 

jo-thijs

Member
jo-thijs Excellent works correctly!!

image_alpha = alpha / (abs (number_one - number_two) + alpha);

Now I have another question, how can I do the opposite effect? that the closer this number_one of number_two the object is more visible, otherwise it will be less visible, excuse me I'm still a noob in game maker
That function already does that.
But if you want the reverse effect, just add a 1-:
Code:
image_alpha = 1 - alpha / ( abs(number_one - number_two) + alpha );
 
Z

Zanget

Guest
That function already does that.
But if you want the reverse effect, just add a 1-:
Code:
image_alpha = 1 - alpha / ( abs(number_one - number_two) + alpha );
Thank you that was just what I was looking for!!
 
Top