how can i make it exact?

well this is my door script but every time it runs, sometimes it goes in 360 degrees because it goes past the closing and it was 270. so basically (270 + 90) = 360 (in unity that = 0) so it keeps going
and of course the opposite way, when its open 90 degrees and starts to close, it goes past 0.
:face_with_spiral_eyes:

var smooth = 2.0;

var DoorOpenAngle = 90.0;

var DoorCloseAngle = 0.0;

var startPosition = 0;

var open : boolean;

var enter : boolean;

var rotateAround : Transform;



function Start(){



startPosition = transform.eulerAngles.y;

if(transform.eulerAngles.y > 264  transform.eulerAngles.y < 300){

transform.eulerAngles.y = 265;

startPosition = 265;

}

if(transform.eulerAngles.y > 300){

transform.eulerAngles.y = 0;

startPosition = 0;

}





}



//Main function

function Update (){



 if(open == true){

  //var target = Quaternion.Euler (0, DoorOpenAngle, 0);

  // Dampen towards the target rotation

  //transform.localRotation = Quaternion.Slerp(transform.localRotation, target,

  //Time.deltaTime * smooth);

  if(rotateAround.transform.eulerAngles.y < DoorOpenAngle + startPosition){

  transform.RotateAround (rotateAround.position, Vector3.up, Time.deltaTime * smooth);

  }

 }



 if(open == false){

 // var target1 = Quaternion.Euler (0, DoorCloseAngle, 0);

  // Dampen towards the target rotation

  if(transform.eulerAngles.y > 3 + DoorCloseAngle + startPosition){

  transform.RotateAround (rotateAround.position, Vector3.up, Time.deltaTime * -smooth);

  //transform.localRotation = Quaternion.Slerp(transform.localRotation, target1,

 // Time.deltaTime * smooth);

 }

 }



}





//Activate the Main function when player is near the door

function activate(){



if(open){

open = false;

}else{

open = true;

}



}

Use quaternions when interpolating rotations. There are a nice set for methods provided by Unity. If your door’s rotation when closed is 0,0,0, then you can use Slerp() to Quaternion.Identity, which is the equivalent of eular 0,0,0. Give it some R&D and post for help if you need. There are quite a few posts on the subject for reference.

A simple Coroutine and boolean to keep track of it’s state would do perfect.

var state=false; // false == closed
var openAngle=Vector3(0,90,0);
var speed=2.0;

function Start(){
	var myOpenAngle=transform.localEulerAngles + openAngle;
	var myClosedAngle=transform.localEulerAngles;
	while(true){
		if(state){
			transform.localEulerAngles=Vector3.Lerp(transform.localEulerAngles, myOpenAngle, speed * Time.deltaTime);
		}else{
			transform.localEulerAngles=Vector3.Lerp(transform.localEulerAngles, myClosedAngle, speed * Time.deltaTime);
		}
		yield;
	}
}

While Lerp should fix any issues where the result will rotate the wrong way, a vector3 linear interpolation will not give nice results if the door opens wide. I also would not recommend using Vector3s to represent rotations (a look at point sure, but not a rotation) because eular (x,y,z) rotations are horrible at interpolation. In the posted code, Unity will be getting and setting to quaternions, I’m sure, so the only real problem would be the linear interpolation, and the extra layers of code.

If I wasn’t on my iPad I would post some code, sorry. You basically just define the rotations and slurp from Quaternion.Identity to and from.

What you are encountering is an annoying problem called “Gimble Lock.” This happens because Unity lerps the numbers along a standard “number line.” So going from, say 1° to 359° is a positive change of 347°, not a negative change of 2°, even though the end result would appear to be the same.

As they’re describing above - the best way to work around this problem is by using Quaternions. Note that you don’t need to understand the math behind them in order to understand how to use them. In general, you just need to know that a quaternion rotation represents a given orientation of an object in space and that you can interpolate between sets/pairs of these.

Quaternion.Identity typically corresponds to a EulerAngle Rotation of x=0 y=0 z=0.

You’ll probably have good luck using both Quaternion.identity and Quaternion.LookRotation. Both are explained in the scripting reference.