Hi
I have a simple scene with a cube balancing on a sphere. The cubes x and z are controlled by user input. Imagine a see saw but3d. Anyway, it all works fine except that the cube spins around on top of the sphere even though the Y rotation axis is constrained and at no point in code do I modify the Y axis.
Here is my script that is attached to the cube:
private float tiltSpeed = 3f;
private float tiltX, tiltZ;
private Vector3 localRotation;
Vector3 tempQt;
private Rigidbody rb;
// Use this for initialization
void Start () {
localRotation = transform.rotation.eulerAngles;
rb = GetComponent<Rigidbody> ();
tempQt = transform.rotation.eulerAngles;
}
// Update is called once per frame
void Update () {
}
void FixedUpdate(){
float curSpeed = Time.deltaTime * tiltSpeed;
//tiltX = Input.acceleration.z + 5f * 2f;
//tiltZ = Input.acceleration.x * curSpeed;
tiltZ = Input.GetAxis ("Vertical") * curSpeed;
tiltX = Input.GetAxis("Horizontal") * curSpeed;
localRotation.x += (float)tiltZ;
localRotation.z -= (float)tiltX;
tempQt = rb.rotation.eulerAngles + new Vector3(localRotation.x, 0f, localRotation.z);
rb.rotation = Quaternion.Euler(rb.rotation.eulerAngles + new Vector3(localRotation.x, 0f, localRotation.z));
}
Is this a bug or am I doing it wrong?
Any help getting the Y axis constrained would be greatly appreciated.
Thanks