# 1 Variable Affected By Multiple Variables

I would like to have a large float affected by multiple other floats. Right now I have this:

``````energy -= thirst + temperature  + hunger  + tiredness;
``````

These variables get bigger every second which means the rate at which Energy decreases is vastly increased over time. I do not want this. Is there a way for energy to be decreased at a rate depending on these variables or would I have to reverse these variable’s affects (such a decrease thirst instead of increase it and add the variables together to equal energy)

``````energy -= (a * thirst) + (b * temperature)  + (c * hunger)  + (d * tiredness);
``````

a b c and d can be set to some decimal value (<1) to reduce the impact of the variables on the energy. You can use these as modifiable stats as an in game skill-tree or some nonsense so they player could acquire some resistance to temperature, for example.

So, above, if a = 0, thirst has no impact on energy. If a = 1, thirst has full impact (Or more if you make a > 1!!).

You go to a hot place. You can simulate this easily by increasing a and b to be > 1.

My approach would be to first figure out what rate I would want energy to decrease at in the worst scenario. So with zero thirst, hunger, temp, and tiredness, the energy will not decrease as player is in top form. Assuming the 4 variables are 0-100:

``````int energyDecreaseRate = 1; //eg. 1 energy per frame
float energyDecreasePerc;

void Update(){
energyDecreasePerc = ((thirst+temp+hunger+tireness)/4)/100;
energy -= (1 * energyDecreasePerc) * Time.deltaTime;
}
``````