Need Help - Player Rotation Values

When I click on my “player” and run play mode and rotate the player around, the Inspector clearly shows the player’s “Y” rotation value changing on a scale of 0-360. Based on that, I wrote a single line of code:

    angle = GameObject.Find("Player").transform.rotation.y;
    Debug.Log(angle);

The debug log is returning values of 0-180 and only positive values. I start out my game at Y rotation of 0. If I turn slightly to the right, my debug log says:

0.3032301

But if I turn slightly to the left from the starting Y rotation of 0, I also get:

0.3032301

I need a full 360 degree range of values or at the very least, a positive/negative 180 degree value. I am using this value to rotate a GUI image (my compass). Any ideas? :face_with_spiral_eyes:

What you see in the inspector isn’t transform.rotation, it’s transform.eulerAngles. Rotation is a quaternion.

–Eric

Juz found up, i answer the wrong way, should read the question twice. Like Eric say, juz use transform.eulerAngle.y or use the transform.Rotate function

– TwisterK

Thanks guys, here’s my simple compass script:

var image : Texture2D;
var size = Vector2(128,128);
private var angle;
private var pos = Vector2(0,0);
private var rect;

function Start() {
    pos = Vector2(Screen.width-(size.x/2),size.y/2);
    rect = new Rect(Screen.width-size.x, 0, size.x, size.y);
}

function OnGUI () {
    //Compass
    angle = GameObject.Find("Player").transform.eulerAngles.y;
    var matrixBackup = GUI.matrix;
    GUIUtility.RotateAroundPivot(-angle, pos);
    GUI.DrawTexture(rect, image);
    GUI.matrix = matrixBackup;
}

You can open up the ‘pos’ variable so you can set those manually or even dynamically. I have it hardcoded to always be in the top-right corner and with some additional code, this could have a drop-down or even be configured in an options menu to allow multiple positions (top-right, bottom-left, etc). Anyway… it works really well as-is for a simple compass.