Search Unity

Animating a door that can open inwards or outwards

Discussion in 'Animation' started by chris_gamedev, May 19, 2019.

  1. chris_gamedev

    chris_gamedev

    Joined:
    Feb 10, 2018
    Posts:
    34
    More door trouble. Who knew that animating doors would be so difficult? (It's probably very easy, but I'm making it seem hard...).

    I have a door which is closed. The door should always open away from the character. To achieve this, I have two animation clips. One which rotates the door +90° and one which rotates the door -90°. Each animation is reversed to close it (thanks again @SilentSin).

    Each one has a trigger which I call in code. Which one is triggered depends on which side of the door you are on. I have confirmed that the logic of which trigger is called is correct. The first time the animation clip plays, it is always correct, regardless of which side of the door you start on. But subsequently, despite calling the other trigger in code, only the original animation clip plays.

    As my code seems correct, it seems like the animation state machine is probably wrong.

    upload_2019-5-19_13-31-38.png

    I have tried various permutations of this, but currently, this configuration has the least weird behaviour as described above.

    I know I'm fundamentally misunderstanding this so I apologise in advance but any help is very appreciated.

    Thanks
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,445
    The transitions each have some kind of criteria. Are they correctly configured? Are you setting the appropriate animator controller parameters from both sides of the door? Are you creating a transition that goes back to center/closed state when complete? (I only see outbound arrows.)
     
  3. chris_gamedev

    chris_gamedev

    Joined:
    Feb 10, 2018
    Posts:
    34
    Yeah there are two triggers. One is called OpenFromInner and the other is called OpenFromOuter. The transition from Default to OpenFromInner has the OpenFromInner trigger as a condition and the other transition has the OpenFromOuter trigger as a condition.

    I think that is correctly configured but I'm very new to animation within the last couple of days.

    The code is simply calling
    animator.SetTrigger("OpenFromInner");
    or
    animator.SetTrigger("OpenFromOuter");
    depending on which side of the door you are on.

    And if you start on the inside, the correct animation plays. If you start from the other side, the correct animation plays. It's just that subsequent trigger plays the wrong clip.

    I'm kind of assuming that there should be transitions from each trigger too and maybe back to default, but things get a bit weird then. I am fairly sure it's something to do with the logic in the animator though.
     
  4. chris_gamedev

    chris_gamedev

    Joined:
    Feb 10, 2018
    Posts:
    34
    I have seen a slight improvement with this approach:

    upload_2019-5-19_18-22-44.png


    And it looks like this:

    https://imgur.com/6cfd3dp

    You can see it is actually working as designed now - the door always opens away from you.

    Only thing is that there are sometimes a few frames when you are opening it from the other side for the first time that it looks like it is opening towards you before opening the other way.

    The open animation also seems to be sped up.

    I feel dumb, I'm sure the issue is staring me in the face.