- Home /
How to smooth accelerometer values
I am new to unity...I just want to smoothen the accelerometer values..so that i have to move GUI label having sniper scope position with accelerometer values(x&y) without any jerk or vibration. I have to start a ray from the midpoint of scope to 3d world where camera is moving..!
Answer by zharik86 · Feb 08, 2014 at 07:00 AM
It is possible to use some frequency filters for rounded value. For example, lowPasFilter, highPasFilter, etc. More detailed information can be found on wiki. It is also possible to use the lerp function,for example(write on CSharp):
float myXaceel = 0.0f;
float myYaceel = 0.0f;
float smoothSpeed = 1.0f;
void LateUpdate() {
Vector3 acceler = Input.acceleration;
//maybe need normalize vector accelerometr
acceler.Normalize();
myXaccel = Mathf.Lerp(myXaccel, acceler.x, smoothSpeed * Time.deltaTime);
myYaccel = Mathf.Lerp(myYaccel, acceler.y, smoothSpeed * Time.deltaTime);
...
}
Answer by frogsbo · Feb 08, 2014 at 06:55 AM
When you have a fairly easy sounding unity question, it has probably been asked many times before, so best try searching on Google 1st, you'll get even more answers than by asking and faster.
Your answer
Follow this Question
Related Questions
How to set GUI X and Y positions from accelerometer.x and accelerometer.y ? 1 Answer
How to set GUI X and Y point according to accelerometer input.? 0 Answers
gui and tilt function 1 Answer
Screenshot certain layers so it doesn't show GUI Button on the image?? 0 Answers
onValueChanged Dropdown in loop 2 Answers