direct and reverse proportion between variables

hi all :slight_smile:
here’s a math question, as an example, since i can’t really formulate it mathematically

I have a cube moving from x = 35 and x = 16 (just random numbers)

and I want a variable to be 0 when the cube is in x=35, and 1 when the cube is in x=16

I’ve been reading the Clamp and the Floor classes, but probably i searched for the wrong word, since what i’m trying to accomplish, is a proportion

My actual scenario is a rigidbody, which drag should be 1 while grounded on a sphere, and 0, beyond the atmosphere radius, so i can take into account the rigidbody distances, but I’m missing how to implement such relation.

thank you, I hope my question was clear.

if x0 is your value for 0
and x1 is your value for 1 then

t = (x - x0) / (x1 - x0);

x is your current value, t a value between 0 and 1 as long as x is between x0 and x1

Use InverseLerp.