- Home /
Question by
Ellie97 · Oct 31, 2018 at 12:00 PM ·
rotationaccelerometertilting
Maze game style rotation
I have a maze which I would like to control with an iPhone's accelerometer. I'm experienced with Unity development but my little brain can't figure out for the life of me how to appropriately achieve a plane tilting dependent on accelerometer. This is what I have currently:
private void FixedUpdate()
{
float xGyro = 0;
float yGyro = 0;
if (Input.acceleration.x > 0.1f || Input.acceleration.x < -0.1f) //dead zone
{
xGyro = Input.acceleration.x;
}
if (Input.acceleration.y > 0.1f || Input.acceleration.y < -0.1f)
{
yGyro = Input.acceleration.y;
}
//Debug.Log("Gyro: " + Input.acceleration);
Vector3 acceleration = new Vector3(yGyro, 0, xGyro);
Vector3 newRot = Vector3.Lerp(transform.rotation.eulerAngles, acceleration, Time.deltaTime * moveSpeed);
transform.rotation = new Quaternion(newRot.x, 0, newRot.z, transform.rotation.w);
Debug.Log("Rotation: " + transform.rotation);
}
Comment
Best Answer
Answer by Ellie97 · Oct 31, 2018 at 05:09 PM
transform.rotation = Quaternion.Euler(-Input.gyro.attitude.x * speed, 0, -Input.gyro.attitude.y * speed
Your answer
Follow this Question
Related Questions
Tilt object acceloremeter limited 0 Answers
Get Accelerometer to rotate 360 degrees 2 Answers
rotating object with accelerometer without changing its original path 0 Answers
Get absolute acceleration data from accelerometer/gyroscope but neglect rotational acceleration 1 Answer
Realtime Object Rotation on iPad 0 Answers