Resetting Ragdoll

Hello!

I’m having an issue with the ragdolls inside Unity. I’m working on a game where the player is able to pick up an enemy and smash or throw him away. This enemy is composed out of 3 prefabs. The master prefab holds the enemy script that controls all the AI etc. The other 2 prefabs are the models. The first one is an animated model and the second one is the ragdoll model. We use 2 different prefabs because we need to be able to disable the ragdoll one for performance.
Now, when the ragdoll is thrown away, we make the ragdoll prefab inactive (using SetActive) and we enable the animated prefab. We also reposition the ragdoll prefab to it’s original position (reset the local and world positions and rotations). The problem is, the ragdoll itself isn’t being properly reset. It still has all it’s rotations and local positions differences (because of the spring values).

I cam across this topic (http://forum.unity3d.com/threads/202510-Cleanly-resetting-a-ragdoll) and I tried some of the solutions. But none of them help. Is there a way to reset the rotations and positions of a ragdoll skeleton back to it’s initial values. Saving the rotations and positions and overwriting them (local positions and local rotations) doesn’t seem to do the trick. Also, I’m not able to use PrefabUtility because we need to be able to do this at runtime in a builded version.

Thank you in advance

Alright I’ve figured out how to reset my ragdoll. By resetting I mean putting the enemy back in his spawned pose. So no IK stuff going on… But because I’ve found this a pretty hard issue to solve, let me share the process.

So, when the ragdoll must be disabled, I do the following step (make sure when the ragdoll is spawned you store the values I overwrite).

  • Reset velocity and angular velocity to Vector3.zero
  • Get all the characterjoints created by the ragdoll wizard in Unity and overwrite them with there original localrotation.
  • Get rid of the position offset created by the springs (yes, we want the spring ability enabled, so a hard reset is necessary)
  • Reset the skeleton’s position, localposition, rotation and localrotation (later we position it back on the master prefab).
  • Foreach Collider reset it’s localrotation.

This seems a bit weird and maybe overkill. But I’m posting it here so when people who want the same kind of behaviour we want have issues, this can be a guideline. Sorry for not being able to post the entire code, but I’m under a NDA.

If someone really needs the spring damper reset code, I might be able to share it, but please ask for it here first. Then I’ll ask my boss :slight_smile:

Cheers guys!

1 Like

By the Spring position offset, you’re referring to the ConnectedAnchor changing as a result of the springs, right?