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;


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 :slight_smile:

Try using the eulerAngles instead - you are accessing parts of a quaternion which are not what you are expecting. (See - unitygems Resources and Information.).

    var angle = transform.eulerAngles;
    ang = angle.y;