Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to blend ragdoll physics with animation?

Discussion in 'Physics' started by donnysobonny, Mar 4, 2019.

  1. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    Hey all,

    I'm wondering if anyone might know how to do something like the movement in party.io (youtube example):


    I'm particularly interested in the movement (not too bothered with the interaction/fighting etc) where it looks as if it's blending ragdoll physics with animation. Does anyone know how I might do that in Unity, either with an asset or a certain technique?

    I was thinking maybe to have a separate ragdoll and animated version of the character, and to lerp the bones of the animated character to the ragdoll but that just seems messy...

    Any help would be hugely appreciated!
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    This stuff is pretty difficult to execute well, I've taken a shot at it a couple times and had pretty sad results. Games like gang beasts really seem to do it well though, so there is a way, and I'd love to see a tutorial or write up describing what somebody did to get it working, though I've never found such a thing. :/
     
  3. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    Hmm that is frustrating, it's good to know I'm not the only one though! Out of interest, what sort of things did you try?
     
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Well the first thing which is a for sure bad idea - is to take a ragdoll setup with a lot of rigidbody parts and joints, and try articulating that with forces. This turns into a real funky non realistic mess of a thing in my experience :p

    Then I tried doing the whole fade to animations from ragdolls type thing, and could never quite get it working at all unfortunately.

    EDIT: Another thing is, after viewing that video - jeesh those guys seemed to have the exact same system as gang beasts? Like.... eerily similar to it... almost identical?!? Makes me wonder whats going on there... suppose it could all just be a coincidence though!
     
    Last edited: Mar 4, 2019
  5. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    Hmm yeah i did wonder about that, trying to make animations using physics joints alone but yeah... I can only imagine how messy that would be. Surely that's not what party.io/gang beasts are doing? It does look like maybe they are doing that but surely not!

    I haven't tried the blending between animations/ragdoll yet but since you can't modify transforms etc of a character where those transforms are being modified by an animation (for example, make the animation control 50% of the motion and the ragdoll the other 50%) I figured it might be worth trying to have one hidden version of the character (the animated one, with an animator component etc) and the visible version would be the ragdoll, and I would lerp the bones in the ragdoll towards the corresponding joints in the animation. I haven't tried it yet because it sounds SO messy, and I expect performance to be terrible, but is this what you tried?

    Yeah, they are super similar! That's what I was thinking, there's also human's fall first and a few others that come to mind that all seem to use pretty much identical looking character motion... so yeah there must be a tool or a technique that we're not aware of!
     
  6. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    They do some sort of thing with the 50% ragdoll 50% animations... if I had to guess I'd say the legs are almost entirely animated as running, yet if they collide with a physics object, it will still interact with that first before following the animation. The upper bodies though, are more elastic and free to move with forces, and the arms do animations for punches/grabs/whatever they need to do, just blending from whatever position they are at, into a start of the animation, then play the animation, and at the end of the anim or in the event of a collision, they go back into physics objects. It is a clever use of IK and physics while the character controller itself is semi-physical too, allowing a fluid look and feel to them, even though they do still have some hard animations.

    I didn't try lerping the bones towards an animation skeleton, though that might be worth a shot - if you can always be checking for collisions and instead use physics if there is ever a collision like these other games.
     
    donnysobonny likes this.
  7. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    there's 3 assets on the store that deal with active ragdolling.

    PuppetMaster
    https://assetstore.unity.com/packages/tools/physics/puppetmaster-48977
    Mecanim Ragdoll Animation Blender
    https://assetstore.unity.com/packages/tools/physics/mecanim-ragdoll-animation-blender-17007
    Active Ragdoll
    https://assetstore.unity.com/packages/tools/animation/active-ragdoll-123749


    I don't know that puppet master uses, active ragdoll has two skeletons on one object or what uncomprehendable thing for me, ragdoll-anim blender has all joints referenced and do some kinda rotations, and there are some opensource hinge-joint type of experiments
    lerping ragdolls to animations is doable (you can even animate ragdolls if I'm not mistaken), and kinda follow animation but don't work for walk for example because of the ground physics they move unnatural/not like the anim.

    it was possible to separately animate limbs in U4 I think, pre-mecanim.
    in mecanim could use two (or more) animated skeletons, and mix in the used bodyparts (root motion again need to be done separately)
    yeah, and magic happens there, between physical position and animated position
    one method is tracking distance between animated rotation and physical rotation
    and not to forget: physical happens after animated in the default execution order, is that right
    ...and recently came up, that there's an undocumented oneliner for execution ordering a script.
     
    Last edited: Mar 4, 2019
    cuongvm2307 likes this.
  8. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    I think what is seen in the video, is made with a system might be for sale, or the author was making a game with I'm not sure. quite nice

    it looks like the hip is controlled. and looks like in-place animation-based.

    I was thinking of this
     
    Last edited: Mar 5, 2019
  9. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    You got that the wrong way around man, you have a ragdoll in-world and "lerp" its bones to the wanted animation while physics is also acting on it.
     
    cuongvm2307 likes this.
  10. jaspercayne

    jaspercayne

    Joined:
    Nov 29, 2014
    Posts:
    5
    I know this is kind of a necropost, but I was actually thinking about this problem recently. In theory, couldn't you create an avatar mask using whatever you want to ragdoll, apply it to the base animation layer, then adjust the layer strength to 50%?

    Doing that you could animate the legs to allow for walking without needing to math it all out procedurally, but mask out everything else so it ragdolls freely with the motion created by the legs. I think.
     
    cuongvm2307 and InsaneDuane like this.
  11. Unity2dBOI

    Unity2dBOI

    Joined:
    Nov 10, 2019
    Posts:
    1
    I'm friends with a gang beasts developer and the technique they use is full on ragdoll. They use forces and they stick a ball inbetween the players legs to help them balance and to help keep the mass right.
    The gang beasts developer which I'm not going to name, thinks that human fall flat might also use that method but I'm not sure about party.io. I'll check out the leg movement with party.io and see if they use the same thing.
    PS: The ball helps get up slopes as well.

    EDIT: Alright I think party.io also uses the same technique since their legs never make contact and they may also be freezing the hips rotation as the hips never move.
     
    DungDajHjep and cuongvm2307 like this.
  12. dvpweb

    dvpweb

    Joined:
    Jan 2, 2022
    Posts:
    3
    Hello. For my part, I trigger the effect of the ragdoll when it should fall (usualy when he encounters an obstacle at high speed). Once the body is stabilized on the ground, I launch an animation so that it gets up. Lots of fine-tuning, but the end result is quite satisfying. Just make a good ragdoll and turn off the animator for it to crumble. Sure, it's not real active ragdoll yet, but it looks like it and the animations stay consistent.

    The ideal would be Unity offers an active ragdoll module with the possibility of assigning an animation percentage to each bone... Otherwise, it's too complex to develop yourself and it must be managed by the native engine in my opinion.

    EDIT :
     
    Last edited: Jan 15, 2022