Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Animation forgetting how to be an animation...

Discussion in 'Scripting' started by ultraviol3nt, Oct 26, 2014.

  1. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    So it's a pretty simple problem. The script is supposed to animate a door. The prints work fine, so I know the conditional portions of the code work, it's just not playing the animation at all.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class UO_Door : UsableObject {
    5.  
    6.     public bool isOpen;
    7.     [System.Serializable]
    8.     public enum DoorOpeningDirection { Inward, Outward}
    9.     public DoorOpeningDirection OpeningDirection;
    10.  
    11.     public override void DoInteract()
    12.     {
    13.         if (isOpen)
    14.         {
    15.             if (OpeningDirection == DoorOpeningDirection.Inward)
    16.             {
    17.  
    18.                 animation.Play("door_closing_outward");
    19.                 print("closing");
    20.             }
    21.             else
    22.             {
    23.                 animation.Play("door_closing_inward");
    24.                 print("closing");
    25.             }
    26.             isOpen = false;
    27.         }
    28.         else
    29.         {
    30.             if (OpeningDirection == DoorOpeningDirection.Inward)
    31.             {
    32.                 animation.Play("door_opening_inward");
    33.                 print("opening");
    34.             }
    35.             else
    36.             {
    37.                 animation.Play("door_opening_outward");
    38.                 print("opening");
    39.             }
    40.             isOpen = true;
    41.         }
    42.     }
    43. }
     
  2. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,353
    Does your door have Animation component?
     
  3. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    Indeed it does.

    Edit: like for my cheesy UDK test material ripoff? :D
     

    Attached Files:

    Last edited: Oct 26, 2014
    elmar1028 likes this.
  4. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,353
    Strange. Everything looks fine to me. Have you ever heard of Mecanim animations?
     
  5. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    I have. But everything I hear about them makes it seem more like it's meant for characters and other organic animation.
     
  6. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,353
    I am using it to make my FPS camera feel real (like dynamic movement etc). Sounds very wrong, but it works! :p
     
  7. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    Per your recommendation, I tried converting it over to Mecanim, but it's still not working.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class UO_Door : UsableObject {
    5.  
    6.     public bool isOpen;
    7.     [System.Serializable]
    8.     public enum DoorOpeningDirection { Inward, Outward}
    9.     public DoorOpeningDirection OpeningDirection;
    10.     public AnimationClip openingAnimation;
    11.     private Animator anim;
    12.  
    13.     public override void DoInteract()
    14.     {
    15.         if (!animation.isPlaying)
    16.         {
    17.             anim.SetBool("isOpen", isOpen);
    18.         }
    19.        
    20.         if (isOpen)
    21.         {
    22.             isOpen = false;
    23.         }
    24.         else
    25.         {
    26.             isOpen = true;
    27.         }
    28.     }
    29.  
    30.     void FixedUpdate()
    31.     {
    32.        anim = GetComponent<Animator>();
    33.        anim.SetBool("isOpen", isOpen);
    34.     }
    35. }
    36.  
     

    Attached Files:

  8. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,353
    Try to uncheck Apply Root Motion.
     
  9. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    That didn't do it. But it's worth noting that the collider moves. Just not the model itself...
     
  10. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    I have had a lot of issues with Unity's animation system just not making sense. Don't feel bad. Try to find an example of what you're trying to do and dissect it, you'll figure it out.
     
    elmar1028 likes this.