# How to find how much an object has rotated?

Hey, I’m trying to find the angle of an object from a certain point. I’ve tried a few things nothing seems to be working properly. I suck at explaining so here’s a little drawing of what I mean:

var findAngle = false;
var findingAngle = false;
var lastPosition : Vector3;
var currentAngle : float;

``````  function Update() {

if(!findAngle) findingAngle = false;
if(findAngle && !findingAngle) {
lastPosition = transform.forward;
findingAngle = true;
}
if(findingAngle) {
currentAngle = Mathf.Acos(Vector3.Dot(lastPosition, transform.forward));
}

}
``````

This tells you the angle between the two vectors - but it’s only good for 180 degrees and it will be positive no matter which way the rotation happens - did you want something else?

#pragma strict

``````var findAngle = false;
var reference : Vector3;
var angle : float;

function Update () {
if(Input.GetKeyDown(KeyCode.N)) findAngle = !findAngle;
if(findAngle) {
reference = new Vector3(1, 0, 0); // Direction 0 degrees is in (currently positive x axis)
angle = Vector3.Angle(reference, transform.position);
if(transform.position.z - reference.y < 0) {
angle = 360 - angle;
}
}
}
``````

Here’s the updated function. It uses the positive x axis as 0 and counts degrees counter-clockwise.

Edit: Cleaned the code up.