Unspottable is a competitive couch party game where you need to punch your friends before they punch you. Blend in the crowd of AI characters, hunt down the other players and use the many different environment specific rules to win the game. "Walk like a robot and punch like a human!"

Post news RSS Blending Ragdoll physics and animation in Unity

This is a short techincal explanation of our system to blend between ragdoll physics and animation in Unity 2019.

Posted by on

Blending Ragdoll physics and animation in Unity

This is a short techincal explanation of our system to blend between ragdoll physics and animation in unity 2019.
It came from the need of adding more robots to the scene by dropping them from the sky, so after being ragdolled on the floor they had to get back to an animated state:

The ragdoll of the robots is fairly standard, they have an almost humanoid skeleton but not exactly.
It can be achieved on humanoid models following this great Brackeys video: Youtube.com

Once ragdolled on the floor, the first step is too figure out if the robot fell on its front or back.
To do that we just compare the vector up of the root bone of our character and the default vector up.

Vector3.Dot(rootBone.up, Vector3.up) > 0

We're only focusing on two cases, up or down but that could be improve to have better animations to get up at different angles.

We can then choose between the two animations:

standingfromback standingfromfront


At that point, we want to blend between the positions of the ragdolled skeleton and the animation.
That's done by calculating the position and rotation of each bone, using their current ragdolled position and their supposed animation position.

So on LateUpdate() after the animation position is calculated:
To get the animated bone position, we have to look at the transform on LateUpdate, but for a real humanoid rig, it should be accessible using Animator.GetBoneTransform (https://docs.unity3d.com/ScriptReference/Animator.GetBoneTransform.html)

Interpolation of position and rotation for each bone, using a blendSpeed variable to be able to tweak the strenght of the blend:

foreach (Bones b in skeleton){
  b.transform.position = Vector3.Lerp(b.transform.position, b.ragdolledBonePosition, blendSpeed);
  b.transform.rotation = Quaternion.Slerp(b.transform.rotation, b.ragdolledBonePosition, blendSpeed);
}

I hope that short explanation helps some of you understand the logic, feel free to come and chat on twitter if you have questions! Twitter.com

And please wishlist on the store page to help us make more content! :)

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Profile
Icon
Unspottable
Platforms
Windows, Mac, XBOX, PS4, Switch
Developer & Publisher
GrosChevaux
Engine
Unity
Contact
Send Message
Release date
Game watch
Follow
News
Browse
News
New
Post news
Share
Related Games
Unspottable
Unspottable Party
Related Engines
Unity
Unity Commercial
Related Groups
GrosChevaux
GrosChevaux Developer with 2 members
Unity Games
Unity Games Hobbies & Interests with 1,819 members
Unity3d Discussion
Unity3d Discussion Educational with 27 members