Decrease a number, from itelf to zero, by exponentially smaller amounts based on another variable

Hi there, i’ve been trying to figure out this for all day, but it seems more complicated than i can handle right now.

With these three variables (DistanceThreshold, CurrentDistance, VarX) i need to decrease “VarX” by exponentially smaller amounts depending on how small the value of “CurrentDistance” is in relation to the DistanceThreshold.

Let’s say these are the values (This is pseudo-code):

DistanceThreshold = 600;
VarX = 40; // 40 is the max value of this variable, the minimum should be 0
CurrentDistance = GetDistance();

Every frame i check if CurrentDistance is smaller than DistanceThreshold. If that is the case, based on how close i am to the target (AKA how low CurrentDistance is), i decrease “VarX” by some amount. But i want to do it exponentially, meaning that the lower “CurrentDistance” is, the smaller the number i subtract from VarX will be.

In a graph, it would be something like this (It’s probably mathematically impossible but you get the idea. I don’t need a precise value for VarX, i just need it to be low, like ~1.2 or below)

https://forums.unrealengine.com/core/image/gif;base64

https://forums.unrealengine.com/core/image/gif;base64

Just use curves (float in your case)
https://docs.unrealengine.com/en-US/API/Runtime/Engine/Curves/UCurveFloat/index.html

I have always used FRuntimeFloatCurve to process falloffs like that
https://docs.unrealengine.com/en-US/API/Runtime/Engine/Curves/FRuntimeFloatCurve/index.html