- Home /
Question by
static_cast · Nov 30, 2013 at 02:07 AM ·
2dcamera rotaterotate objectz axiscusm rotation
Rotating Produces Odd Results [Unity 2D]
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);
}
}
Comment
Best Answer
Answer by robertbu · Nov 30, 2013 at 02:10 AM
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.