Changing parameters gradually with modifiers

I think the foundation for this logic is flawed leading to code that doesn’t make sense leading to headache as you try and force it to make sense. For example, you want the “stealth rating” determined by how “visible” the player is which itself is based off of the actions the player takes + the environment those actions are taking place in to “gradually” change up or down. But, if I were in a dark room, completely hidden and then turn the flash light on, my “visibility” rating would go from 0 to 100 INSTANTLY would it not? That is what your rules state above. So if that instantly sets visibility to 100, how can you then also want it to “gradually” increase? This is flawed logic. You can’t write good code from flawed logic. Second, if my visibility is say “30” and then I hit the “run” button I am INSTANTLY more visible, +60 by your rules. How is that supposed to be a “gradual” change? Going from stationary to running happens in one frame, maybe two, how can your visibility change over a longer period of time than that? Doesn’t make sense. If you want “gradual” changes, what you need to do is say something like this. Player starts at visibility of 10, if player starts running add 5 visibility points per second up to a max of 100. So if the player runs for a short burst and finds cover he is temporarily more visible by a few points maybe 15 for the 3 seconds he was running, but if he continues to run for longer periods of time he becomes more likely to be spotted and this correlates with a continuously increasing visibility value. When he reaches a safe spot, visibility should decrease by 2.5 per second. This makes sense since running to an area of cover doesn’t INSTANTLY hide you (assuming your AI is even mildly intelligent). So my suggestion, have a timeline on loop, have a variable for “visibility”, and have a variable for “delta visibility”. Every action the player takes that increases visibility, say running with a flashlight will add the effect together. So running is +5 pts, and the flashlight is +10, thus cumulatively for each second the player is running with a flashlight visibility will increase +15. Then say the player finds cover, but still has the flash light, the delta would be 15 - 5 (not running) - 3 (found cover) so the player will net +7 visibility even though he is in cover because he is using a flashlight. But it will be less than had he been running with the flashlight. This makes a system that is logical and allows you to sum the players choices both positive and negative into one cohesive value for whether or not the player is becoming (see now it happens over time) more or less visible.

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?

how can you then also want it to “gradually” increase? This is flawed logic.
Well, relatively gradually. In my current state it changes in about 0.4 seconds. Not enough to be an effect on the mechanics, but feels nice for the UI.

Seems that I managed to solve this. Here’s blueprint:

The idea is that each condition is ruled via bool value, an it adds either its intended value to the parameter, or 0 if bool is false.

I made a function that’s being fired every 0,2 seconds via delay node, doing what’s pictured and then triggering my other function that sets player’s visibility with gradual lerping in those same 0,2 seconds. That literal float will eventually be replaced with value derived from luminosity of the trace under the player, I hope, and then it’ll become fully functional system.