Hey guys im trying to get a heavy breathing sound to play at a certain volume according to how much stamina i have
if(CurrentStamina < MaxStamina * 0.75)
{
TiredNessScale = //RATIO BETWEEN 0 and 1 0 being silent 1 being loudest
if(TiredNessScale < 0)
TiredNessScale = 0;
else if(TiredNessScale > 1)
TiredNessScale = 1;
Debug.LogError(TiredNessScale);
}
Basically what i want the above code to do is make my ratio equal a number between 0 and 1, 0 being 0 and 1 being MaxStamina / 0.75. So far ive tried math.lerp, inverse lerp and smooth damp.
Anyone? please? How would i achieve this?
TirednessScale = 1 - (CurrentStamina/MaxStamina);
You don’t mean MaxStamina / 0.75, you mean MaxStamina*0.75, and you also don’t want high Tiredness when your stamina is high as you wrote it…
Correcting what you wrote, I think you want the following:
- If my CurrentStamina is low, close to 0, I want my TirednessScale to be high, close to 1
- If my CurrentStamina is high, close to 75% of max, I want my TirednessScale to be low, close to 0
- If my CurrentStamina is high, over 75% of max, I want my TirednessScale 0 as I’m not tired then.
And the formula doing this is:
TirednessScale = 1f - Mathf.Clamp(CurrentStamina/(MaxStamina*0.75), 0f, 1f);
Debug.Log(TirednessScale);
And with this formula you don’t need your first if-block and you also don’t need to check for tiredness being outside of 0 or 1, the formula does it all. Just replace your complete block of code you posted with the two above lines