Question by
david.struverson · Feb 29, 2016 at 12:02 PM ·
gyroscopephonegyro
How to make 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
Your answer
Follow this Question
Related Questions
Ignore gyroscope yaw 0 Answers
Gyroscope controls ufo game? 0 Answers
Gyroscope Controls for FPS 0 Answers
Moving.Rotating a Raycast with Respect to Rotation 1 Answer
Im trying to make a player move 360 degree gyroscopic movement on my phone 0 Answers