Question by
animeman0 · Apr 17, 2016 at 04:27 PM ·
c#gyroscopetransform.rotation
Rotating game object using gyroscope - C#
What I'm trying to do is make the player rotate with the rotation of the gyroscope. However when I test it nothing happens.
Code:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
Gyroscope gyro;
Quaternion rotation;
float move;
public float rotationSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
move = Input.GetAxisRaw("Horizontal");
Quaternion rotation = Quaternion.Euler(Vector3.forward * move * rotationSpeed);
//transform.rotation = rotation * transform.rotation;
transform.rotation = Input.gyro.attitude;
}
}
Comment
Answer by Jabeebus · Dec 19, 2017 at 09:14 AM
If you are basing the gyroscope on a phone or tablet, you have to check if the device supports gyroscopes because most smart phones and tablets don't have that feature. If you are referring to the gyroscope on mouse movement, you need to clamp the rotation of the object with the mouse X and mouse Y input.
Please specify which gyroscope you are referring to.