How do i check the angles between 2 positions?

For instance, i have a object facing a direction, i want it to rotate towards his right, until he have rotated 45 degrees and then some to the other side, like a patrol.

I tried something like this:

`// my object is turning to its right`

`transform.Rotate(0,Time.deltaTime * 5, 0);`

`Vector3.Angle(position.position.forward, transform.forward));`

where 'position' is my initial and transform.forward is where im looking at since im rotating.

But what he does is check the angle between the world front Z and not the position of my object. Did i make myself clear? hahaha

Well, I'm not sure what `position.position.forward` is. I might recommend naming your variable something different so it is easier to read later when you are debugging and such. Given that, I might try something like this:

var lastRotation : Vector3 = Vector3.zero;
var angle : float;
var desiredAngle : float = 45;

function RotateYDegrees (desiredAngle : float) {
     lastRotation = transform.forward;
     angle = 0;
     while (angle < desiredAngle) {
         transform.Rotate(0,Time.deltaTime * 5, 0);
         angle = Vector3.Angle(lastRotation, transform.forward));
         yield;
     }
}

function Start () {
    RotateYDegrees(desiredAngle);
}

That script should work, but I didn't test it, so there might be a few bugs/typos. You could also do it in Update(), and then you would probably use an `if` statement instead of a while loop, but it would all do the same thing.

The thing is, i have 3 methods. One that makes the robot walk, other one that makes the robot patroll and another one that makes the robot follow the player. I have a boolean flag to turn it on or off and its be calling in the Update() function.

The method above works, but the while puts the frames/s really low, like its lagging. So i tihkn its not the best way to do. I tried something like this:

`function PatrolAtStop(position, angle)

`{

    print(anglePatrolled);
    lastRotation = position.forward;

if (angle < 60) {
    transform.Rotate(0,Time.deltaTime * 20, 0);
    anglePatrolled = Vector3.Angle(lastRotation, transform.forward);
 }   
 else
 {
    patrolling = false;
    anglePatrolled = 0;
 }

}`

The thing is, that sometimes the var angle jumps from 0 to 70 and it doesnt rotate. Any insights on that?