Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question How do I get an animation to work with an object the character is holding?

Discussion in 'Animation' started by Marscaleb, Jun 8, 2024.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,041
    I have some character models I hired someone to make for me, and I'm almost ready to hire someone to make the animations.
    But I'm realizing that I'm going to have a problem with some weapons the characters need to hold.

    I didn't think much of it earlier because I know that an object can just be parented to the bone in the model. slap it in there, maybe adjust it's position offset a little, and then the object will move perfectly in synch like he's holding it.
    But now I realize that I'm going to need several motions where the weapon won't be perfectly matching the position of the hand. He'll have one anim where he holds a musket by the butt, another by the stock, and then there's the sword animations he holds by the handle... I can't just parent it to the hand because that won't match for all animations. (Maybe the sword, but not the musket.)

    I know that within Unity I can create an anim file where I can move the object around as I see fit, but I'm not creating the character animations within Unity, I'm hiring a freelancer to create them. He'll create them in another program and send me fbx files with the animations. Trying to animate the weapons separately within Unity itself would be a huge extra hassle.

    The only other option I can even think of is to modify the character model to contain an extra bone that could be used for the weapon slot. This would require me to send the character models back to my modelling guy, and then those models would no longer match the skeletons in my other models, and I'm not even sure where that bone would need to be connected to.

    Is there some other option I am not considering? Is there some other way to animate an external object with a character? How should I be pulling this off?
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,596
    The character owns its armature full of actual bones. Your artist can author the character. Your animator can author the official bones. This is all in its own asset.

    You can add additional anatomical "landmarks" or empty objects that are relative to the actual bones for your own purposes. The palm of the hand, the place on the side of the hip where a scabbard hangs, the place a pendant falls on the chest, or a backpack sits on the back.

    The weapon is likewise a multi-part object, possibly with moving components.

    You can add additional "grips" or empty objects that are relative to the places on the weapon where hands should align in different situations. Right hand for trigger, Left hand for support, a scabbard alignment helper, etc.

    In general, consider an "empty" to be a bookmark in space, and it's always relative to some other transform in space. Use them liberally to identify and mark key locations around mechanical grips in prefabs like weapons, or anatomical landmarks on prefabs like characters.

    You may also find useful a function like the one I shared in https://forum.unity.com/threads/align-two-objects-at-a-child-transform.1387179/ to achieve those alignments. Align the sword to the hip so the sword-scabbard-helper matches the hip-scabbard-hanger. Align the musket to the right-hand at the muzzle to allow the left hand to repack another shot. And so on.

    Lastly, if you HAVE to animate the "grips" or "landmarks", they're often procedural animations, but they can be hand-animated also. These can also be secondary animations kept separate from the original characters' animations.
     
    spiney199 likes this.
  3. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,041
    The weapon isn't so complicated; it's just for show. Literally the only thing it interacts with is the guy holding it. The model is only a single static mesh. I just need it to move properly with the character in different animations; holding it like a parade march, and holding it while he's running.

    Maybe I gave the wrong impression by saying weapon. It's just an object. An object he is holding in different ways for different animations. But the animations need to be made with the object's size and position in mind.
     
  4. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,596
    Sure. Doesn't change anything though-- you have multiple spots along the object which you want to align to a landmark on the character's body which may be somewhere near the hand bone.
     
    spiney199 likes this.
  5. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,041
    Okay, but what about movements that don't move exactly with the hand bone?
     
  6. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,596
    One hand is typically the parent of the thing being held. Then you get motion along with that hand for free.

    If you want both hands on the object, you can use an IK solution to maintain contact between the hand and the object at the grip location. Usually, you make the object the child of the right hand, and use IK to pull the left hand into position, but you could use both IK on both hands if you want the object to be animated by some other means.
     
  7. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,041
    I mean like, what if I want an object to be dropped or thrown in a pre-animated way? What if an object held needs to roll in a way that a hand isn't being moved?
     
  8. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,596
    Dropped: set parent to null.

    Thrown: set parent to null, give it velocity. Or animate it in world space.

    Roll across from hand, up arm, across chest, down arm, into other hand: set parent to null, animate it in character's local space, set parent to other hand when it's done.

    I think it's time you start playing with these ideas hands-on instead of prevaricating on the forums. See what works for you. Learn from what doesn't work. Get halfway to something you like, and with the knowledge you've set into your mind, re-read what I wrote above and decide if it resonates or not.
     
  9. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,212
    You can also use animation masks, and in effect apply 2 different animations, one for the arm, one for the rest
     
  10. peaceamit

    peaceamit

    Joined:
    Jul 18, 2015
    Posts:
    13
    I believe the question here is if weapon and character have separate animations, how does it works?

    If weapon has no animation, parenting the weapon with character hand bone or any other bone will work. The weapon will move as if it is part of the character and animate accoring the the bone it is attached to.

    In below scenario - your animation will break.
    In case weapon has animation, then weapon will automatically animate on top of character animation. It will create complex animations but needs to be scripted and designed carefuly.

    Take for example of sword slash animation. If character is picking something up from ground and sword is having slash animation, it will be a totally wierd animation.

    Here is a custome workaround solution:
    • Take an empty game object named CharacterBase.
    • Parent your character to CharacterBase.
    • Parent the sword to CharacterBase.
    • Now both Character and sword will animate independently and in close proximity.
    • Use IK packages like FinalIK to map character hands to sword position.
    • You will need to ensure that sword animation is not too far/ is withing character reach.
    • Also, you need to ensure that sword animation and character animation complement each other. Like a standing character can do horizontal slash animation at shoulder height.
    • You will have to apply script on CharacterBase to ensure MevementDelta from CharacterAnimationis applied to CharacterBase.
    • Enable disable IK weights as required for your usecase.
    This solution should allow separate development for your character and sword animation.
    Cheers.
     
    Last edited: Jun 11, 2024