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