I have a script that calculates the distance between the player and an obstacle (boat).
In another script, I’m mapping that value between 0 and 1 to adjust the Fill Amount of a UI Image.
What I need to incorporate is when the player is moving further from the boat, the fill amount decreases at half the rate it’s increased at when the player is moving closer to it.
So the player moves close to the boat, it increases quickly, and when they move away, it decreases slowly. Here’s my code for the UI:
Image CircleBarImg;
private float stressAmt;
public static float fillAmt;
public float boatReach;
void Start () {
CircleBarImg = this.GetComponent<Image>();
}
void Update () {
stressAmt = boatDistance.dist - boatReach;
fillAmt = MapAnxiety (stressAmt, 0, 100, 1, 0);
if (fillAmt >= 0){
fillAmt = fillAmt * fillAmt; //fillAmt increases exponentially
}
CircleBarImg.fillAmount = fillAmt;
}
private float MapAnxiety(float value, float inMin, float inMax, float outMin, float outMax){
return (stressAmt - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
Thank you