I have a character with ragdoll setup, but all the components disabled
it is parented to another master object, with a slight offset (about -1.2)
when I want to activate the ragdoll, I unparent the character from the parent controller model and activate the rigidbodies and colliders.
but when I do this the ragdoll object instantly moves position fairly drastically. (though it is still in the correct pose, and working correctly as a ragdoll)
I unparent it by setting obj.transform.parent = null. this seems to work, and looks correct in the hierarchy window. is this the wrong way to do it ?
I also tried printing (and examining in inspector) the position of the object before and after un-parenting it, and unity prints the same values (it doesnt think it moved)… even though it is physically very different. (below where it should be, under the floor)
I’ve tried various ways of forcing a different position onto the un-parented object… all of which do move it somewhere, I just can’t seem to make it stay exactly where it was before and after un-parenting. (even if I record the position before, and set it to that after unparenting)
what is the correct way to unparent an object, and/or how can I do this without the object moving, when I do so please ?
the only thing that seems like it might affect things is that my parent object is scale 1 and the character is scale .05
However the error in the new positional offset seems unrelated to this scale in any way… (its not a multiple or divisor of the object’s original position or offset from the parent)
To make things clearer, what position coordinates does it show for your rag doll object under the parent object?
Also, did you have some code changing the objects position before you started experimenting with changing the position to the original one?
the rag doll object is at 0, -1.2, 0 relative to the parent object.
but when I unparent it, it instantly appears 10 or 20 units or more below the parent (although the world co-ordinates appear not to change)
There is no code that changes position of the ragdoll… there are no scripts on it.
There is code controlling the parent object and moving that. (think of it as the parent object is a car… the child object is a character, and when you crash, it unparents the child, and turns on the rigidbodies, so it flies out of the car at time of crash.
If you unparent an object, it maybe will accept the coordinates from its position where it was before. So the character object. So if your character object is at 10 or 20 in the world, you rag doll will use these coordinates. Maybe you have to reposition it right after parenting
try setting the characters local coordinates to zero for testing
try the same scenario without unparenting and see if the same problem presists
That way if the problem presist you can rule out that it has something to do with either of those.
Also, is the character object part of the ragdoll setup or is it just a parent object for it?
In that case I would also try printing out the location of the ragdoll root instead.
Report back the changes that appear or even if you find the solution. It would be interesting to know what actually caused it.
I personally think it is the case of the character object staying in the correct location and the ragdoll root doing the 20-30 unit jump.
Thanks for the comments and the ideas… they helped me sort thtough things…
I added cubes (with 0,0,0 offset ) as children to all my relevant objects, then watched what happened after unparenting…
actually, all the objects were exactly where I thought they should be… but the rigidbody root/pelvis had fallen or moved away from the character. So even though the character looked normal, and was at the same place as the cube (so was his mesh / skeleton etc… the rigidbody was elsewhere. So when I stopped the animation and activated the rigidbody, the skin moved to where the ragdoll was
So even though the whole ragdoll rigidbody was asleep, the root / pelvis still moved somehow… (even though the actual character root didn’t
I dont know how it moved, but at least I can now reset it to where it is supposed to be.
so its onto the next issue… trying to make the rigidbody look good, rather than a jiggling, stretchy pile of mush
thanks again for help
So does the ragdoll root start falling when the game runs or is it in the wrong position from the start or does it go there after you activate it.
I would suggest selecting the root object in the inspector while you are running the game to get more info on it. Maybe it activates its rigidbody at some point when it is not supposed to. I find that it is the best way to find out exactly what is going on with the object. Also opening the Scene View and Game View together may reveal more information.
the ragdoll root is the same as the player/character… so it doesnt fall, the game updates just fine until a crash happens, and its unparented… at that time the car is at the collision position the character is unparented, the skeleton(with ragdoll) then has all the ragdoll rigidbodies and colliders turned on (switched off from sleep mode for rigidbodies, and enabled for colliders) and the skeleton moves to its new weird position at that time.
So it could be stopping the animations that does it… or starting the ragdoll bones… I’m not sure.
the hierarchy looks like this…
car
…character
…skeleton
…mesh
so unparenting character… leaves car and character in expected positions… but skeleton suddenly moves somewhere else
all the individual bones in the skeleton are still in the correct pose (from jsut before the crash), just the skeleton root is some place else.
I’m still perplexed, but at least I can fix things now.
Your ragdoll root node is the hip or around there, right?
When you unparent it, if your car was at 0,0,0 your hip will be at 0,0,0
It’s correct in the Inspector and in what it’s doing… You just have to get the local transform before unparenting!!
I am having the same problem and while reading your description the answer just came to me.
I am going to try it out and report back.