Question by
david.struverson · Feb 28, 2016 at 01:32 AM ·
phone
Having GameObject follow phone's gyro
I've been trying to have a gameobject be controlled by my phone - however, when I actually implement the code, the object, when facing up for example, will change its z rotation while I'm changing the phone's y rotation - however, because my phone is facing up, it reads the change as z. How can I have a local rotation from my phones gyro like I have a local rotation for the actual object? using UnityEngine; using System.Collections;
public class positionmang : MonoBehaviour {
public float speed;
private float step;
void Start() {
Input.gyro.enabled = true;
}
void Update() {
step = speed * Time.deltaTime;
Quaternion phoneRotation = new Quaternion (Input.gyro.attitude [0], Input.gyro.attitude [2], Input.gyro.attitude [1], Input.gyro.attitude [3]);
transform.localRotation = Quaternion.RotateTowards (transform.localRotation, phoneRotation, step);
}
}
Comment