What is the best way to smooth a float value over ?

Hi Folks… this may seem like a weirdly simple question and I’m kind of embarrassed to ask. But I haven’t seen it anywhere: what is the best (smoothest, controllable, performant) way to smooth constant incoming values (float, vector, rotator, etc) in Blueprints?

Like for instance, something like smoothing a mouse float input.

Try implementing a moving average:

  1. You create a list L of length N, this is where the last N values are stored.
  2. You keep track the current number of valid values in L using variable LVC.
  3. You also store the sum of all values stored in L using a variable LS.
  4. When a new value comes in you put it a the end of L. If L is full then you throw away the oldest value, shift the rest and set then new value as last.
  5. Then you update the LS by subtracting the thrown away value and adding the new value.
  6. And finally you can calculate the rolling average: LS / LVC.

By playing with N you can fine tune how “twitchy” the output is.

1 Like

i believe your talking something akin to the following picture. i was thinking a similar idea but i initially though about changing the sample rate rather than the number of samples but it still accomplishes the same thing.

oh and my example may not be perfectly optimized fyi.

or depending on the data being processed and how it needs to be used you could just divide, round, multiply, which will give you an approximated value but wont account well for large spikes in the value.

@ZoltanE & @ThompsonN13 … makes perfect sense, thank you both! :slight_smile:

I guess I was kind of hoping that something inbuilt… most likely InterpTo… to smooth such a stream of values (float, rotator, vector, etc)?

There is Interp To for each variable type; FInterp To, VInterp To, etc.

thanks @… I know… what I was wondering was if there was a way to use this node (or another interpolation node) to smooth a stream of values over ?

Could you use a Timeline with a curve float?

@… this also did kind of occur to me, but I’m not sure how it would work with a value …to be smoothed out… coming in on each frame. I can understand how a timeline would work to blend from one set of values (say 0 = mouse input float strength) to another (1 = full mouse input float strength).

But I’m not sure how a timeline would smooth out a stream of mouse input float values… I’m open to suggestion though:)

There’s a way to approximate the moving average idea without storing more than one value. Rather than storing the last N values and computing a moving average, you can do this cheap way by just storing one previous value instead. It’s not as accurate, but often good enough depending on how the values are changing over .

If you want to smooth as if you had a 10-sample moving average, you could do this

Smoothed = (NewValue + (PreviousValue * 9.0f)) / 10.0f
3 Likes