- Home /
Input Acceleration low-cut + smooth
I'm trying to rotate my camera based on the Input.acceleration.y. The usual Problem is that the acceleration values are not smooth and very sloppy.
So i tried to low-cut and smooth the acceleration. Here is what i tried.
That does not work proper, but i cant find out what to do to get it working.
float newrotation = 0;
float tmp = Input.acceleration.y;
if(Input.acceleration.y >= lastacceleration.y + 0.05 ||Input.acceleration.y <= lastacceleration.y -0.05)
{
tmp = Input.acceleration.y;
tmp = Mathf.Lerp(lastacceleration.y , tmp,Time.deltaTime *20);// tmp
}
else
{
tmp = lastacceleration.y;
}
newrotation = tmp *90f;
lastacceleration = Input.acceleration;
camerago.transform.localRotation = Quaternion.Euler( 0,0,newrotation);
Answer by biohazard · Jul 26, 2011 at 09:36 AM
if you want a less-sensitive accelerometer then i suggest you save the Input.acceleration into a variable and divide it by a certain number to vritually smoothen it's sensitivity, then use this variable instead of the real Input.acceleration.
Hope i helped
bio
"edit":
If you're looking for smoother steps concerning your acceleration, you can interpolate them using Mathf.Lerp
link to reference : http://unity3d.com/support/documentation/ScriptReference/Mathf.Lerp.html
The big problem it that the input is in range -1 to 1 in steps of 0,1 , that means 20 steps for 360 (or 180 not sure now) degrees. That make it like jumping and not smooth rotating like it should.
Im not rely sure why i posted the code i used.
i tried already to use $$anonymous$$athf.Lerp but i cant get it working like it should.
tmp = $$anonymous$$athf.Lerp(lastacceleration.y , tmp,Time.deltaTime *20);
@fff$$anonymous$$alzbier try replacing Lerp with Clamp, it's what i used to interpolate between rotations
Just to make sure... Clamp is not what you are looking for... It has noting to do with interpolation.
Your answer
![](https://koobas.hobune.stream/wayback/20220612155311im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Tilting the Player Object while moving it with Input.acceleration 0 Answers
Smooth value in Input System 0 Answers
Airplane smooth acceleration problem 0 Answers
Input.acceleration Y and Z are the same? 1 Answer
Incremental acceleration with Imput 1 Answer