Dynamic Ragdoll
Try it out and let me know what you think, any suggestions, questions, or feedback is welcome.
Unity package:
__DynamicRagdoll - Google Drive
on GitHub (probably the most up to date version):
https://github.com/tiredamage42/DynamicRagdoll
So recently I’ve been messing around with getting some functional ragdolls working in Unity, and I felt like sharing the results with the community
The standard Unity ragdolls created by the ragdoll wizard were super unstable for me, and unaffected by whatever animation they were coming out of. Which was really jarring when a running ragdoll would drop straight down.
I found the following thread and package and it gave me some really good results!
https://forum.unity.com/threads/animfollow-active-ragdoll-is-now-free-to-download.220812/
Unfortunately, I found myself spending too much time tweaking the values to keep it stable, while trying to balance not doubling up on fixed time steps, as well as tweaking values that weren’t even doing anything
So instead of trying to make the follow algorithm super stable enough to mimic an animation, I changed it to toggle between the animated model and the ragdoll only when it’s needed.
That way the physics are still affecting it as it’s ‘falling’, and when it’s fully animated, it just renders the character.
By calculating the velocity of the animation bones in late update and setting them in fixed update (as opposed to adding forces like in AnimFollow), the velocity can be maintained for a longer period of time in a more stable manner, which gives the illusion of the ragdoll ‘attempting to stay upright’
The effect was good enough since i didnt really need a fully physics driven character (unless it was actually ragdolled) and now I can keep the project’s fixed time step unchanged.
When it came to getting back up the joints and rigidbodies kept getting snagged and becoming unstable again, so I implemented the blend transition i found here:
__http://perttuh.blogspot.com/2013/10/unity-mecanim-and-ragdolls.html__
which turns off the physics and blends the rigidbodies on the ragdoll to the animated position.
Now both transitions look really good in my opinion.
The AnimFollow package from above used a specific character and ragdoll set up that was specific to that
“Ethan” character it comes with, which had an extra collider.
I’m no 3d modeller, when it comes to humanoid characters I use the mixamo pipeline myself.
So I made some scripts that would let me quickly add a ragdoll to a humanoid mixamo rigged model at runtime, or in the editor at the push of a button.
The ragdolls they make are easily tweaked using scriptable object behaviors, so changes to joint limits, rigidbody masses, or other values can be easily made per ragdoll bone in the editor, without having to constantly drag 10+ transforms into the ragdoll wizard every-time, or dig through the hierarchy finding a lower arm joint component!
And thanks to the beauty of Scriptable Objects, changes made during play mode are saved afterwards
With this system, making a ragdoll is as easy as:
- adding the Ragdoll component (included in the package below) to the model
- assign a ragdoll profile scriptable object (with all the settings per bone)
- either press the button in the inspector to prebuild or let it build on Awake
-Syd
Some things I still have to figure out:
- [×] rag dolling on the stairs going downwards doesn’t exhibit normal gravity…
- figure out some way to incorporate the arms or extra leg forces to mimic someone trying to stay balanced
- a better dismemberment system, (actaullly cut off the limb instead of making it disappear)
Update 9/9/19
- Added several custom components that act as physical objects that can “impale” rag dolls and other rigidbodies. Showcased as ammo types, where you can add damage modifications to them
- implemented “complex” rigidbody grabbing that allows for freedom along certain axes intuitively.
Update 9/2/19
- Implemented a simple dismemberment system, and per limb damage multiplier system (showcased in ActorRagdollLink.cs)
- Added per bone data, that lets us keep any custom information per bone, showcased in the damage multiplier system mentioned above
- Edited demo scripts, so interaction with the ragdoll system is contained within: ActorRagdollLink.cs, PlayerControl.cs, and CharacterMovementRagdollLink.cs
- Ragdoll on collisions is incorporated as a feature in the system, no longer a demo script
- Implemented a system to “grab” ragdolls (showcased in PlayerControl.cs)
Update 4/5/19
-
removed the AnimFollow pd control method
-
removed the physics step delay when going ragdoll
-
refactored some demo scripts in order to show a how a character controller can interact with the ragdoll controller (CharacterController.cs)
-
added a script showing how to deal with ragdoll on collisions ( CharacterCollisions.cs )
-
Fix for ‘falling up’ stairs included in the charcter controller script
-
Fixed ‘gliding forward’ issue when ragdoll isnt upright
Here’s a demo of the collisions controller:
Update:
I updated the package to include a different method for following the animation.
By calculating the velocity of the animation bones in late update and setting them in fixed update (as opposed to adding forces), the velocity can be maintained for a longer period of time in a more stable manner, which gives the illusion of the ragdoll ‘attempting to stay upright’