calibrating a gyroscope controlled tilt platform(Android)
Hey y'all, so I am trying to make a platform tilt with gyroscope controls. When I load the game the platform is already tilted as my program seems to create a constant torque based on my phone's physical location relative to the y axis. I need to be able to set my phones returned location to (0,0,0) or create a torque that can oppose the constant movement of the phone so that these controls are more manageable. Any ideas?
public class balance : MonoBehaviour {
public float torque;
public Rigidbody rb;
void Start() {
rb = GetComponent<Rigidbody>();
}
void FixedUpdate() {
Input.gyro.enabled = true;
rb.transform.Rotate(Input.gyro.attitude.x, 0, Input.gyro.attitude.z);
}
}
Answer by Sawula · Jan 02, 2017 at 12:07 PM
using UnityEngine;
using System.Collections;
public class Gyro : MonoBehaviour {
Vector3 rot_ini;
public float _speed;
void Start () {
rot_ini = transform.rotation.eulerAngles;
}
// Update is called once per frame
void Update () {
transform.rotation = rot_ini + (new Vector3(Input.gyro.rotationRate.y,Input.gyro.rotationRate.z,-Input.gyro.rotationRate.x)*_speed);
}
}
Adjust the axis as needed in the new Vector3 I'm using this for my gravity but it should work for rotation
When I put that code in my script, it says: Cannot implicitly convert type Vector3 to Quaternion. What is it that I need to change about the new vector3?
Hey, sorry hadn't checked this in a very long time
Try changing every instance of "Vector3" to "Quaternion" Should work