x


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!

more ▼

asked Aug 07 '11 at 04:59 PM

Dreeka gravatar image

Dreeka
129 50 62 65

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Aug 07 '11 at 06:54 PM

sneftel gravatar image

sneftel
1.7k 7 9 20

Thanks :)

Aug 08 '11 at 12:24 PM Dreeka
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3331
x2168
x193

asked: Aug 07 '11 at 04:59 PM

Seen: 1214 times

Last Updated: Aug 08 '11 at 12:24 PM