how to get a float value based on altitude (0 - 1)

hi! I want to add some air density. I know, there is a function, where i can set the min and max. and a value. based on that it should give me a number between 0 and 1 basen on the altitude value

its something like that:

            float min = 0f;
            float max = 200000f;
            float value = 50000f;
            float airdensity = maths.something(min, max, value);
            //airdensity = 0.75f??

Should be simple.

Lets just make our own formula for it.

Let value = 50 and max = 100

50% of 100 = 50
50% = 0.5
0.5 * 100 = 50
rearrange
0.5 = 50/100 (value/max)

So, we have 50, (“value” in your case) and we have 100 (“max”)
When we divide them we get a proportionality.

But given that your air density is 0.75 with those numbers, I assume you want inverse, so just 1 - calculated value.

It’s different if your min isn’t 0 though. Use max - min for max in this case.

Should be (Val - Min) / (Max - Min)

1 Like

this thread has some options too, for remapping ranges:

The straightforward answer is Mathf.InverseLerp:

This is a special case of the remapping functions discussed in the above-linked thread.

thanks! thats exactly what I need! I just multiplyed the wing lift factor with that value. that simulates a kina realistic space.