- Home /
direct and reverse proportion between variables
hi all :) 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.
Answer by hathol · May 20, 2012 at 05:10 PM
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
for your fictional scenario this would result in
t = (yourValue - 35) / (16 - 35);
that's the value where your object currently is (so its x position or whatever you want to use)
got it, it stands for the dynamic variable, that is actual distance, in this case. brilliant, now it gives me 0 when grounded and 1, and then above, when reached the desired threshold. i'll elaborate on it. thank you again.
Answer by Eric5h5 · May 20, 2012 at 04:41 PM
Use InverseLerp.
thank you, Eric, but that doesn't look like fitting my gap.
i'm on something like
rigidbofy.drag = 1/(distancefromground/upperatmospherethreshold)
where basically, atmosphere radius should be tweakable, so whatever value the user is going to choose, when distance from ground is 0, drag is 1, and as it approaches the atmosphere threshold, drag proportionally decreases, until reaching 0.
$$anonymous$$athf.InverseLerp looks like different to me, or am I missing something ? thank you again, anyway !
Your answer
