- Home /
Best way to rotate a door
So i have this setup (see picture) and I want to make a script that will rotate the door by rotating the hinge (hinge is parent of door). So if I rotate the hinge, the door will open/close.
Now my question is, how should I do this? Do I need to use Eulerangles, Vector3.RotateTowards, RotateAround, transform.rotation, quaternions,... I would like to know the most simple and elegant option with a smooth rotation, and that if I want to rotate the hinge to like 270 degrees, the door won't move clockways, but the system (Unity) will automatically calculate the 'fastest route' or the 'shortest way'. Thank you very much for your valuable time!
Answer by Ezio1302 · Jan 10, 2015 at 06:32 PM
Have you considered using animation to move the door? You could just make an animation file, and then call it within a script. Here is a sample script from MC HALO:
var DoorOpen : AnimationClip;
function Update (){
if(Input.GetKey(KeyCode.A)){
animation.Play("DoorOpen"); // This is playing the animation which will be stored in the Animation variable above this will be your door animation.
}
}
I don't want to use animation because an animation wouldn't be applyable to every door, ty for your input though :)
In that case, you may want to check the scripting manual. Here is an entry for Transform.Rotate: http://docs.unity3d.com/ScriptReference/Transform.Rotate.html