- Home /
Accelerator.x rotating camera.z - problems with intermediate values
Hi all, I'm using Input.acceleration.x to steer an object on mobile devices. When one tilts the devices I would also like to counter rotate the camera.z in order to keep the world horizontal at all time.
private float zRot = 0f;
void Update() {
float targetRot = -Input.acceleration.x*90f;
zRot = Mathf.Lerp(zRot,targetRot,Time.deltaTime*5f);
transform.rotation = Quaternion.Euler(new Vector3(0f,0f,zRot));
}
When I rotate the device the camera doesn't seem to get the right z rotation. Almost as if the values from the acceleration aren't linear. But off course they are. It looks fine when I hold the device in rounded 90 degrees intervals, but when I hold it in 45 degress the world is not completely horizontal. Let me demonstrate this using an image:
The blue line represents a graphical line in the app. The red line is just an illustration of a real world reference.
Let me also just point out that my evidence that the world is not horizontal isn't very scientific. I just hold the device and compare it to real world horizontal references.
Anyone here knowing what I'm doing wrong?
Thanks!