- Home /
Door rotating the wrong way around.
My door is supposed to open for a couple seconds then close. It opens fine but when it has to close it doesn't rotate backwards it keeps going a full 360.
case DoorState.CLOSED:
{
Debug.Log(Quaternion.Angle(transform.rotation, Quaternion.Euler(0, 0, 0)));
if (Quaternion.Angle(transform.rotation, Quaternion.Euler(0, 0, 0)) > 1)
{
Debug.Log("BACKING UP");
transform.RotateAround(pivot.position, pivot.transform.up, Time.deltaTime * speed);
openTimer = openTime;
}
break;
}
case DoorState.BANGING:
{
break;
}
case DoorState.OPEN_IN:
{
if (Quaternion.Angle(transform.rotation, Quaternion.Euler(0, 90, 0)) > 1)
{
transform.RotateAround(pivot.position, pivot.transform.up, Time.deltaTime * speed);
openTimer = openTime;
}
else if(openTimer < 0)
{
state = DoorState.CLOSED;
} else
{
openTimer -= Time.deltaTime;
}
break;
}
Answer by ADiSiN · May 14, 2020 at 09:42 PM
Hi!
It's because transform.RotateAround function take 3rd variable as an angle, not step, what means that you should specify if you want to rotate in specific direction. Simply change positive speed to -speed when you want to rotate it back.
You also can use animation for something like that and just play it when necessary, but that's up to you.
Hope that helps.
Your answer
![](https://koobas.hobune.stream/wayback/20220612234152im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Resetting transform's original position and rotation after using transform.rotateAround 1 Answer
Orbit around orbiting object (transform.RotateAround) 1 Answer
How to rotate an object around a screen point (mousePosition)? 1 Answer
RotateAround Limitations 2 Answers
Rotation promlems past 90 and 270 3 Answers