I want to use the iPhone gyroscope to simulate the behaviour of a kife moving forward and backward. I’m trying to use user acceleration from the gyro. I think I’m on the right way as debugging values from user acceleration y axis I get values near 0.1 when I move the iPhone forward and -0.1 when I move backward.
This is the code I’m using:
acceleration = Input.gyro.userAcceleration.y;
if (Mathf.Abs(acceleration) < 0.015) acceleration = 0;
velocity += acceleration * 10f * Time.deltaTime;
transform.position = new Vector3(transform.position.x + velocity * Time.deltaTime,transform.position.y,transform.position.z);
The problem is that knife always move forward, without any user interaction on the iPhone. Input.gyro.userAcceleration.y seems to return lot’s of noise.
What can I do?
Thanks!