I want to turn an Object by lets say 10 degrees on the Y-Axis.
I wrote: transform.rotation.y+=10;
I thought that would be the most logic. But the Object turns itself by a incredible… ehh… little value: -5.008956e-06
Can anybody explain that?
Thanks for your attention =)
Transform.rotation is a Quaternion. According to the reference, “[Quaternions] are based on complex numbers and are not easy to understand intuitively.” Thus you almost never access or modify individual Quaternion components (x,y,z,w);
In order to rotate the amount you want, look at Transform.eulerAngles. But you cannot modify eulerAngles directly. Instead you have to do something like:
var v3T : Vector3 = transform.eulerAngles;
v3T.y = v3T.y + 10;
transform.eulerAngles = v3T;
There are a number of other ways to rotate something as well including (as Mathew0123 mentions), using transform.Rotate();
Alright, since I really hate doing it that way (and it is not working for me either, but I never rotate this way).
I use this and it works perfectly for me.
It will add 10 every time it is called
var rotateSpeed : float;
rotateSpeed = 10;
function Update () {
transform.Rotate(Vector3.up * rotateSpeed);
}