Rotating Door

Hi, I have a problem: when I create a door with Blender3D and import this on Unity 5, I create an animator for that, then I do a simple animation where the door rotates to 90 degrees. So I have three animation: one for opening the door, one for closing it and the last for idle door. But when I want parent this door to a GameObject (the trigger) the animations break themself: the rotation of 90 degrees is totally destroyed. What can I do for fixing this problem? Please Help.

Try using

Quaternion.Slerp()
     - or -
Quaternion.Lerp()

to slowly move the rotation to the wanted rotation. You could have a script like this:

var openRotation: Quaternion; // Rotation when door is open
var closedRotation: Quaternion; // Rotation when door is closed
var open = false; // Is door open?
var openSpeed: float; // Speed at which door opens

function ToggleDoor () {
    open = !open; // Toggle open boolean
    if (open) // Move rotation to closed
        transform.rotation = Quaternion.Slerp(transform.rotation, closedRotation, openSpeed);
    if (closed) // Move rotation to open
        transform.rotation = Quaternion.Slerp(transform.rotation, openRotation, openSpeed);
}

**NOTE: ** this is untested. It should work but if not, tell me! Also, you’ll need to set the open and closed rotation variables manually.

If you want to be able to open/close the door from the inspector, put the if statements in:

function Update () {}

i solve it: i have put the gameobject as Child instead of Parent