I’ve been working on a rhythm game in unity 2d, and I found something odd: Rotating an objects z-axis to the value of 1 makes it 90 degrees, -1 to -90 degrees, and anything else to 180 degrees. Hm?
#pragma strict
var arrow : Transform;
var pos = new Array();
var rotation = new Array();
function Start()
{
pos = [-0.9, -0.3, 0.3, 0.9];
rotation = [1, 180, 0, -1];
var direction;
for(var i = 0; i <= 16; i++)
{
direction = Random.Range(0, 4);
var clone = Instantiate(arrow, Vector3(pos[direction], -2.4, 0), transform.rotation);
clone.transform.rotation.z = rotation[direction];
Debug.Log(rotation[direction]);
yield WaitForSeconds(1);
}
}
Transform.rotation is a Quaternion, a non-intuitive, 4D construct. The x,y,z,w values are always in the range of 0.0 to 1.0. If you want to deal with angles, you can use Transoform.eulerAngles. Note it is best to treat ‘eulerAngles’ as write-only. There are multiple euler angle representations for any physical representation, and Unity can change the representation on you.