Changing parameters gradually with modifiers

In my game I want to implement a stealth system. Currently it is implemented in form of a float parameter in range of 0 to 100. AI can detect player if the parameter is higher than 50 (or other value based on the difficulty setting, that is not important). So, pretty rudimentary.

Now the system: I want the value to change gradually (Or better put, with small lag), because UI element that tells player how hidden he is uses value to modify itself, and abrupt changes look awful. So I implemented that with a timeline and event that calls to it, and output of the timeline is used to lerp between new value and old value. Simple so far.

Now comes the problem: the visibility value is supposed to be determined by tick via the system determining the illumination of player’s surrounding, Thief style. I don’t know how to implement it so for now it’s just constant 100, which supposed to be value of a brightly lit area.

And then there’s modifiers. This is where my headache began. Those are:

  • Walking: visibility +25
  • Running: Visibility +60
  • Being in a safe spot volume: Visibility -100
  • Turning on the flashlight: Visibility +100 (no matter what)
  • Enemy detected player: Visibility +100 (no matter what, to prevent being able to hide while in a line of sight)

And there might be more later if I decide to complicate system further. Issue is that they can be in almost any combination. So I don’t know how to manage that with timeline. It works with each of them individually (visibility + modifier, then lerp that with current visibility via timeline), but as they applied sequentially, each new one overrides the old, so when they end, the value doesn’t return to what it should be. I tried to fix that by storing value before mod and then after mod ended re-apply that stored value via same timeline thing… This worked until I found out that if you enter safe space (become fully hidden), turn on flashlight (become visible again), leave the safe spot, then turn off the flashlight - the value returns to that of a safe spot, since it was the last stored value. So it’s a hot mess I’m trying to untangle. Any help please?