- Home /
Transform rotation 180° becomes -5.008957e-06?
I wrote two simple scripts: The first is:
using UnityEngine;
using System.Collections;
public class Cube : MonoBehaviour {
public GameObject goSide;
public Side sideToon;
// Use this for initialization
void Start () {
goSide = new GameObject("NewSide");
goSide.AddComponent<Side>();
goSide.transform.parent=this.transform;
goSide.transform.localEulerAngles=new Vector3(180.0f,90.0f,0.0f);
}
// Update is called once per frame
void Update () {
}
}
The second is this:
using UnityEngine;
using System.Collections;
public class Side : MonoBehaviour {}
I created a cube, attached the cube Script. When playing the inspector shows X Rotation= -5.008957e-06 (???)
When using other numbers strange results appear. When using 90.0f everything is fine.
The rotation in Game seems correct. Some aftereffects occure. Whats going on?
Answer by GameForger · Mar 03, 2013 at 03:48 PM
How do I write that code then?
There are lots of different ways of calculating and setting the angle. Typically if you are dealing with eulerAngles, you maintain your own Vector3, and you do your calculations on that...then you set the rotation. Think of eulerAngles as thing you can set but should be very cautions how you use the data you read from them.
Answer by robertbu · Mar 03, 2013 at 10:31 AM
-5.008957e-06 can be rewritten as 0.000005009857 or in other words zero. If you look at your Y and Z rotation, they likely are not what you expect either. For many rotations, there are multiple different combinations of x,y and z values that are the same rotation. Unity has just picked a different combination from the one you expect (but the rotation is still the same). This can cause problems for code that reads the eulerAngles and expects particular values, but I don't see that issue in the code above.
Your answer
Follow this Question
Related Questions
Floating-point errors while assigning transforms 1 Answer
transform.position.x brings up error 1 Answer
Bone Not Rotating? 1 Answer
BCE0023 error 2 Answers
How do I set an objects euler rotations to match the objects transform in C#? 1 Answer