Euler angles doesn't give correct value.
print(Camera.main.transform.rotation.eulerAngles.x);
I'm trying to restrict my mouse look script so that once the camera is looking straight up or down only Mouse X input is used for further rotation unless the Y Mouse input direction takes it away from the "fully down" and "fully up" positions (i.e. without letting the camera go upside down)
The above code shows that the returned eulerAngle.x is incorrect, and doesn't match the value shown in the editor. It starts correct, but once it hits 90 degrees it reduces the value, whereas the editor correctly shows the rotation as e.g. 100 Degrees.
Is this another bug? If not it certainly seems to be designed to make life difficult for people.
How do I access the correct euler rotation angle as displayed in the object editor?
There doesn't seem to be a simple way around this feature-gap. Here is the simple mouse look I came up with, which works exactly as any normal person would expect. So far no bugs, but it's always possible...
public class Simple$$anonymous$$ouseLook : $$anonymous$$onoBehaviour {
public int lookSpeed=200;
void Update(){
if (Input.Get$$anonymous$$ouseButton(1)){
Camera.main.transform.Rotate(Vector3.up, $$anonymous$$athf.Lerp(0, Input.GetAxis("$$anonymous$$ouse X") * lookSpeed, Time.deltaTime), Space.World); // always rotate around up axis
float angle = Vector3.Angle(Vector3.up, Camera.main.transform.forward);
if (Vector3.Dot(transform.up, Vector3.down) >= 0f) { // we are sideways or upside down, so only accept $$anonymous$$ouse input in return direction
if (angle >= 90f && Input.GetAxisRaw("$$anonymous$$ouse Y") > 0) {
Camera.main.transform.Rotate(Camera.main.transform.right, $$anonymous$$athf.Lerp(0, Input.GetAxisRaw("$$anonymous$$ouse Y") * -lookSpeed, Time.deltaTime), Space.World);
}
else if (angle <= 90f && Input.GetAxisRaw("$$anonymous$$ouse Y") < 0) {
Camera.main.transform.Rotate(Camera.main.transform.right, $$anonymous$$athf.Lerp(0, Input.GetAxisRaw("$$anonymous$$ouse Y") * -lookSpeed, Time.deltaTime), Space.World);
}
} else {
Camera.main.transform.Rotate(Camera.main.transform.right, $$anonymous$$athf.Lerp(0, Input.GetAxisRaw("$$anonymous$$ouse Y") * -lookSpeed, Time.deltaTime), Space.World);
}
}
}
}