- Home /
How do you remove jitter from input.gyroscope.attitude?
I have my camera rotation equal to input.gyroscope.attitude in each update. The idea is that the phone orientation is used to orient the game camera like in the real world. The problem is that the camera is way too jittery with this code and needs to be smooth.
I tried doing something like:
Quaternion.Slerp(transform.rotation, new Quaternion(-Input.gyro.attitude.x,-Input.gyro.attitude.y, Input.gyro.attitude.z, Input.gyro.attitude.w), Time.deltaTime * smooth);
But this is still pretty jittery no matter what variable I put as smooth.
What can I do to smooth things out?
Try a running average. Ins$$anonymous$$d of taking the current attitude value, remember the last 5 (for example) and then take the average of those 5.
I tried averaging but it is still horrible. I don't know what to do anymore. See my implementation below. I tried increasing the count, I tried with a delay(implementation below, it kinda stabilize it but only because it adds artificial lag), without delay, with slerp, without slerp...Nothing works and I'm Getting really frustrated:
//quatQueue is a queue of quaternion
//at each update
if (quatQueue.Count >= 5)
{
quatQueue.Enqueue(Input.gyro.attitude);
quatQueue.Dequeue();
Vector4 avgr = Vector4.zero;
Quaternion tempQuat = quatQueue.Peek();
Quaternion firstQuat = quatQueue.Peek();
int index = 2;
foreach (Quaternion singleRotation in quatQueue) {
$$anonymous$$ath3d.AverageQuaternion(ref avgr, singleRotation, quatQueue.Peek(), quatQueue.Count);
}
transform.rotation = Quaternion.Slerp(transform.rotation, new Quaternion(-avgr.x, -avgr.y, avgr.z, avgr.w), 1);
quatQueue = new Queue<Quaternion>();
}
else
{
quatQueue.Enqueue(Input.gyro.attitude);
}
Answer by Emperor · Oct 21, 2016 at 07:13 PM
My problem was not the Gyroscope but instead the large numbers used as position coordinates for the camera. In other words, my camera was at something like x:7000000 y:4000000 and this doesn't work accurately in the Unity Engine. It resulted in a lot of jitter.
If you end up on my question and you don't use large numbers for your position, then slerp, averages, filters are all valid methods of reducing the jitter.
Your answer
Follow this Question
Related Questions
How to set child position and rotation fixed respect parent? 0 Answers
Why the control with gyroscope inverted when I make 180 degrees turn? 1 Answer
Virtual Reality - Android Gyroscopic Camera - Pitch and Roll Issues. 1 Answer
Gyroscope smooth transitions (minimizing jerk from tiny movements) 1 Answer
Rotate gyroscope-based camera over it's Y axis by swiping 2 Answers