- Home /
This question was
closed Mar 10, 2014 at 04:47 PM by
vexe for the following reason:
The question is answered, right answer was accepted
This post has been wikified, any user with enough reputation can edit it.
Check angle
I need to know the angle of rotation of an object and i wrote this code:
Vector3 moveDirection;
Quaternion angle;
float ang;
void Update{
moveDirection = this.transform.position;
angle = this.transform.rotation;
if(Input.GetKey(KeyCode.UpArrow)){
ang = angle.y;
if(ang >= 270f && ang <= 90f)
moveDirection.x += 0.2f *Mathf.Cos(angle.y);
else if(ang >= 90f && ang <= 270f)
moveDirection.x -= 0.2f*Mathf.Cos(angle.y);
}
But it doesn't work, i don't know why, it never enter in the if or else.... Why ? Please comment this question :)
Comment
Best Answer
Answer by whydoidoit · Mar 10, 2014 at 12:47 PM
Try using the eulerAngles instead - you are accessing parts of a quaternion which are not what you are expecting. (See http://unitygems.com/quaternions).
var angle = transform.eulerAngles;
...
ang = angle.y;