So I’m afraid this is more of a “basic maths question” than a scripting question, but I’ve got no better place to ask.
I have three floats, exposureValue01, exposure01, aperture01. As the names imply, they’re all values from 0 to 1. I’d like to make it so that as I increase exposure01, exposureValue01 increases. At the same time however, I’d like to make it so that increasing aperture01 decreases the value of exposureValue01. I’m sure there’s a simple solution for this but the entire method is escaping me. Any help would be great, thanks.
// Depending on where these values changes I would either use OnValidate or a property.
// This triggers when a value in the inspector has changed
private void OnValidate(){
// Example.
// Exposure of 0.71 means that Aperture is (1 - 0.71) which equals 0.29
exposureValue01 = (1 - aperture01);
}
That just takes one of the variables I’m working with into account though. I need to make it so that both aperture01 and exposure01 are doing something.
Right now I have exposureValue01 = (exposure01 + aperture01) / 2f;, but this gives an “incomplete” value.
Whoops, looks like the rest of my post got cut off for some reason.
Basically, I always want the key value to be able to move between its set values of 0.1f and 5f. By using the average, there are configurations where the key value will only make it to 2.55f, which is a problem. Here’s the relevant code in Update:
This sounds like plain game design to me. What is your goal? Do you have fixed numbers as examples? For instance if exposure = 0.2 and apeture = 0.3 then exposureValue = ?
There are many solutions but the rules are the important thing and we can’t answer that for you.
But here is another random example that does what you want: exposureValue = exposure - apeture; Now you could scale the values or add limitations to adjust it the way you want.