Its a simple script yet I can’t get it to work. Whenever I run it, transform.eulerAngles.x always stops at 90. What’s up with this??!
function Update () {
transform.eulerAngles.x += 1;
}
Btw, I need to be working with eulerAngles.
Update: Its almost as if unity clamps the angle between 270(or -90) and 90. I have not clamped the angle myself.
This issue comes up frequently. There are multiple euler angle representations for any physical representation, and Unity/Quaternions can change the representation. For example, run this code:
function Start() {
transform.eulerAngles = Vector3(180,0,0);
Debug.Log(transform.eulerAngles);
}
What you will get back is (0,180,180)…the same physical rotation but a different euler representation. One solution is to maintain your own Vector3, and treat eulerAngles as write-only.
var v3 = Vector3.zero;
var speed = 25.0;
function Start() {
transform.eulerAngles = v3;
}
function Update() {
v3.x += speed * Time.deltaTime;
transform.eulerAngles = v3;
}
Use: transform.localRotation.eulerAngles.x or y or z instead of transform.localEulerAngles. This lets you get a full 360 range.