Animation Playing But Object isn't moving.

I’m using two scripts. I created a cube and made it a door pivot with a door script created two animations one open door and the other close door. My problem is that the pivot turns but the door doesn’t turn with it.

Both scripts for people to use through a tutorial.

Door.CS

using UnityEngine;
using System.Collections;

public class Door : MonoBehaviour {
   
    private int m_LastIndex;
   
    public void PlayDoorAnim ()
    {
        if(!GetComponent<Animation>().isPlaying)
        {
            if(m_LastIndex == 0)
            {
                GetComponent<Animation>().Play("DoorOpen");
                m_LastIndex = 1;
            }
            else
            {
                GetComponent<Animation>().Play("DoorClose");
                m_LastIndex = 0;
            }
        }
    }
}

InputHandler.CS

using UnityEngine;
using System.Collections;

public class InputHandler : MonoBehaviour
{   
    void Update ()
    {
        if (Input.GetMouseButton (0))
        {

            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            RaycastHit rayCastHit;

            if (Physics.Raycast (ray.origin, ray.direction, out rayCastHit, Mathf.Infinity))
            {
                Debug.Log ("Mouse Click!");
                Door door = rayCastHit.transform.GetComponent<Door>();
                if(door)
                {
                    door.PlayDoorAnim();
                }
            }
        }
    }
}

Credit to this tutorial

Is the door set to static?

The door is set to static.

Thats your problem :wink:
Static = does not move

Turn static off on the door.

1 Like

So that works now but, now the door is sideways when it is not static…that doesn’t make sense?