Search Unity

Animations and you

Discussion in 'General Discussion' started by derf, Jun 28, 2018.

  1. derf

    derf

    Joined:
    Aug 14, 2011
    Posts:
    356
    I posted this question in the animation forums but thought it may be of discussion quality in the general forums as well.

    When creating animations for objects that have more than one animating element. Do you put all the animations into one animation or do you tend to create individual animations and key frame-chain them together?

    Example:

    I have an animation on a door that has a separate handle mesh so I can also animated that separate from the door. My initial animation has the door handle animating from key frame 0-10 (rotates on it Y-axis to 30 degrees and back to 0 degrees) and the door animates from key frame ~5-60 (which rotates it 90 degrees on its-Y axis) when it is opening. So the illusion look like the player turned the handle and opened the door.

    However this than requires me to create a separate door animation called door_closing which animates the door from the open state (Y-axis 90 degrees) to the closed state( Y-axis 0 degrees) without the handle moving.

    So I have for each type of door three animations door_opening, door_closing, door_locked. The door locked animation simply attempts to rotate the door handle only a few degrees back and forth for about 60 frames. Basically it goes from 0 degrees to about 12 degrees and back again and it does this 4 times.

    So Key Frame 0-10 rotates 12 degrees. Key Frame 10-20 rotates back to 0 degrees. It does this on Key Frames 20 - 30, 30 - 40, 40 - 50, 50 - 60.

    This works fine in all tests; but now I am trying to determine now if this is the best practice approach or is it better to create an animation file by element and have them keyed by their frames in a chain event structure.

    So I create an animation for the door handle called turn_handle and it goes from key frame 0-10 rotating the handle 30 degrees on its Y-axis than back to 0 degrees. There is also a door animation called open_door that starts from key frame 8 with door position 0 but goes from 8-60 rotating the door 90 degrees on its Y-axis.

    So when the player triggers the door animations it calls for turn_handle and open_door and they play simultaneously with their key frames being properly timed together giving the proper illusion to the player. In this way I can simply reverse the animation speed from 1.0 to -1.0 on the open_door and it "closes" the door.

    In this fashion (I haven't implemented it yet but will test it), I would have only 2 animations, turn_handle and rotate_door. When the door is locked I play the turn handle animation from key frame 10-60 with the audio file for locked door, while Key Frame 0 - 10 rotates the handle by say 28 degrees and back to 0; or what ever frame rate I need to go with for aesthetic purposes.

    So how do you approach such things (whether it is a door, car, machine, monster, weapons, etc.)?

    What is your take on these two approaches?

    Do you use animations or simple quaternions and math for this?
     
    theANMATOR2b likes this.
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I use animations as much as possible, being a animator.
    For me - I think both methods are fine approaches. I look at it this way, if the door handle will never rotate on it's own unless the door is opening, I would probably combine the two separate mesh elements and reduce the number of animations, then use bones to rotate the door and door handle. This reduces the number of animations by one and allows for only one animation controller, less assets, less files, less overhead (for me).
    If the door handle does (as in your example) rotate independently sometimes when the door does not open/close I would keep the handle separate and animate/trigger when needed.

    A follow up question might be - do this externally or internally? I prefer simple animations like traps/doors/2-3 linear state anims (without deforming/skinned mesh) to be created in engine, especially when they have a low number of states. If the contraption is rigid rather than organic and the states are low I tend to gravitate towards creating the animations in Unity, maybe even the hierarchy if separate pieces are required for destruction or other reason.
    If the model is complex, I usually gravitate towards external bone based animation. With timeline separated animations. I'm just faster/better in 3D app than in Unity.
     
    BrandyStarbrite likes this.
  3. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    I use animations for this, because they're easy to preview at design-time. If elements always animate together, I generally just have one animation clip that animates all the pieces in one file – this makes it easier to preview, too. (Plus, I find animation events, which one needs to sequence multiple animations together flexibly, to be pretty fragile.)

    I use tweens or interpolation in code when the source / destination points of my animations are dynamic, although I wish there was a way to define a value in an animation as variable somehow without sampling your own animation curve.

    For example, if I draw a card into my hand in a card game, and the card and the hand might be in any arbitrary place when that occurs, then it makes no sense to use an animation clip as they stand. But for an opening door, absolutely.
     
    theANMATOR2b likes this.
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    Erm. (-_-)

    You can have two animation layers in animator controller..

    One layer for the door, and one for the handle.

    Four animation clips.
    1. Door closed.
    2. Door open.
    3. Handle pressed
    4. Handle handle released

    Each of them with a single keyframe.

    Then you can make a statemachine that will separately control opening closing of the door.
    And pressing releasing the handle. Speed would be controlled by transition.

    In case door animation is COMPLEX, then you'll need four clips - "Door open" -->"Door closing" -->"Door closed" -->"Door Opening", which still won't touch the handle.

    That's how I'd go about it. I'd also use separate animation clips (instead of jamming it all into one clip), and for something trivial I would've created them in unity. Unity has a massive problem where it for some insane reason uses Euler Angles instead of Quaternions for animating within the editor, but for simple stuff those are manageable.
     
    theANMATOR2b likes this.
  5. derf

    derf

    Joined:
    Aug 14, 2011
    Posts:
    356
    For things as simple as door animations I do them in Unity (assuming it is a very simple process).

    As too animation layers; I was looking into using layers in the animator controller. Haven't done that as of yet. Is there any good tutorials or documentation on it? Youtube perhaps or a Unity Tech Tutorial under Learning?