Trying to smooth out ‘jitter’ or random ‘shivering’ motion of tracked virtual objects in an AR project.
Is there something equivalent to a ‘remove spikes’ filter in Unity or C# in general?
I’ve tried the Mathf.SmoothDamp method but it doesn’t do exactly what I am trying to achieve
The logic would be more along the lines of simply if change in motion is too abrupt, please ignore
One way is a simple low-pass filter: instead of feeding the input value directly through, average it with a previous value, send the average through, and then update the previous with that average.
In pseudocode:
x = inputValue
average = (x + previous) / 2
previous = average
output = average
This will make things slightly less-responsive, but might be all you need to get rid of jitters.
You can do this with individual values like rotations along axes, or else with entire vectors. It’s best to experiment with what works best.
You can also make the mixing function asymetric, like so
average = (x * 5 + previous) / 6
That will make it more responsive to new input by using more of the new value, less of the previous.
average = (x + 3 * previous) / 4
And that would make it less responsive, even more low-pass filtered.
Thanks. Position is relatively straightforward. Rotation using Quaternions is a bit more of a head scratcher.
And I assume when using Time.deltaTime it should always be called from Update?
On the contrary, if you’re using Update then use Time.deltaTime. FixedUpdate would use Time.fixedDeltaTime. and if you want movement during Update even when Time.timescale is 0 (i.e. paused) then use Time.unscaledDeltaTime.
The real takeaway is to simply use the Time class to avoid jitter due to variable framerate. exactly which type of update you use doesn’t really matter so much.
It won’t solve sudden jumps from major frame drops, but it will smooth movement overall on stable FPS.
Thanks. Great info. In my case I don’t think jitter is connected directly to framerate variation. But Time.deltaTime still makes a lot of sense. Jitter in my case is almost entirely a result of the limitations of the Vuforia tracking engine.