- Home /
EulerAngles.x stops at 90???
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.
Answer by robertbu · Jun 19, 2013 at 06:58 PM
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;
}
Works like a charm! Thanks! Unity really needs to fix the whole eulerAngles deal.. This isn't the first time I ran into something like this.
It will never be fixed. For rotations, Unity uses Quaternions for a number of valid technical reasons. Euler angles is just a representation of the Quaternion, and when you pull a euler angle back out of a quaternion, you are not guaranteed that the values will be the same as the ones you put in. In theory, you should be able to write code to normalize the rotation so that you can have an expected value, but it is just easier to maintain your own Vector3 as I've done above. And there are other possible ways to solve this problem.
Also you wouldn't want to increment the x angle by 1 every Update, since that's framerate-dependent.
Yeah, I know Eric. It just seemed like a simple way to express my issue.
Answer by holyfot · Oct 08, 2020 at 04:03 AM
Use: transform.localRotation.eulerAngles.x or y or z instead of transform.localEulerAngles. This lets you get a full 360 range.
Your answer
Follow this Question
Related Questions
Object makes random jumps in rotation 1 Answer
Trouble Spawning Bullets with proper rotation 0 Answers
How can I store the individual values of EulerAngles on a Database then re-apply 2 Answers
Camera rotation behaving strangely 2 Answers
Trying to tween the rotation of a cube in x and z and having trouble 2 Answers