Door open animation by script

Hello,

I would like to animate a door to open smoothly by rotating rotating on the y axis from 0 to 90 degree. I have the door’s pivot placed on the right place, so if I rotate it by 90 degree, than it will be on the right place.

However, I dont know how to make the rotation smooth, so the rotating time would take 1-2 seconds, instead of doing it instantly.

Can someone help me with this?

Thanks!

You can either use the animation editor to make an opening animation, or you can use a simple script. I suggest doing it both ways, just so you have a good idea of how the two methods work. For the former, see the “Animation View” section in the reference manual. For the former, you’ll have an Update() method which (assuming the door is supposed to be open) gets the rotation out of the transform, uses Quaternion.RotateTowards with a “toRotation” corresponding to the open rotation and a “maxDegreesDelta” formed by multiplying Time.deltaTime with your desired speed, and puts the resultant quaternion into transform.rotation.

follow the link [Unity 3d tutorial] Triggering a door animation from mouse click select - YouTube
its quite good