Monday, May 25, 2015

Ragdolls


Everyone loves ragdolls! It's not like they're a necessity, but throwing enemies around with the GravGun looks stupid without them. We encountered some problems and found solutions to them and that's what this post is about.


How the ragdolls are set up


  The ragdoll wizard is a good starting point for human characters, but for our needs it was only just that, a starting point. When shooting a character with the GravGun, the root rigidbody gets a mighty impulse force push. Since the ragdoll character consists of several rigidbodies, one for each joint, the push needs to go to all of the joints to get the character flying properly. If one doesn't do that, the victim flies in a chaotic manner with twists and turns. In other words, it looks like crap.

A few things that needed tweaking:

  • More mass was introduced to the joints when problems occurred with low mass rigid bodies
  • Joint/limb collider sizes needed to be bigger to prevent joints going through walls when moving fast (it still happens at times though)
  • Box colliders needed to be changed to capsules
  • Drag, angular drag and rotational limit adjustments were necessary for individual joints - foots and forearms especially
  • Some limbs separate from their parent joints for some reason, which was fixed by adding a simple script to the joints which copies their original position transforms back to them in LateUpdate() - the solution was found here.  (for the keen eye or mobile user, the issue is visible on the .gif above, but was later fixed)

  Ragdolls are needed for non-human characters as well and here is where it all goes manual. It's not a big deal, one just needs to add colliders, rigidbodies and character joints to necessary bones manually.  We haven't yet implemented rag dolls to our bot characters, but it's next on the todo list among a million other things.

Performance


  Initial tests proved the ragdolls to be fully usable on mobile, but there's some difference in the behavior on mobile compared to desktop for some reason. Further tweaking is needed for drag and angular drag values and joint rotation limits need to be adjusted even further. Right now the ragdolls seem a lot more rigid on mobile and it's not something I'm happy with.

  Some optimization was done by making all the rigid bodies on the joints kinematic, disabling the LateUpdate() -ragdoll fix, and disabling their colliders until the ragdoll is needed. These components are then activated on demand, and again disabled if the character wakes up. So far so good.

That's it for this post. Thanks for reading!


-Sami Kuronen