Why does this affect the rotation.z
My code for the program is below, and I intended it change the x and y angles based on the mouse. But for some reason, the Z axis is also affected.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CamerRatator : MonoBehaviour {
public float rotationSpeedCamVert;
public float rotationSpeedCamHor;
public float vertRot;
public float horRot;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
vertRot = rotationSpeedCamVert * Input.GetAxis ("Mouse X");
horRot = rotationSpeedCamHor * Input.GetAxis("Mouse Y");
transform.Rotate (horRot,vertRot,0.00f);
}
}
Thanks so much!
Answer by HenryStrattonFW · Feb 19, 2017 at 02:34 PM
This is likely due to rotation in unity being managed and modelled as Quaternions. This means that when you set specific values via the eulerAngles, or rotate based on the 3 axis, it may not result in expected values when it goes into quaternion space and back out to euler angles again.
Edit: Just to clarify, the reason you can specify set euler angles, then read them back as something different is because a single rotation can be specified by a number of different eulerAngle expressions, so depending on what the quaternion is doing in the background, the set you provide may not be the set you get back out, but they still represent the same rotation in terms of direction.
Not 100% on this, but it is the best explanation I can come up with for why this would occur.
Thanks, do you know then how i would be able to change this so the Z rotational axis remains the same?