Page 1 of 1
Ragdoll Q.
Posted: Sun Jun 03, 2012 3:45 pm
by ruggy
Hi,
I have ragdoll working but sometimes I want to return to using animation (after a few seconds, say), but later might want to go into ragdoll again. To clear the ragdoll should I remove all the Entities and AngularMotors (and re-create them later if required)? I remove them by taking them out of the Space and setting them to null. I tried this earlier but it didn't seem to work, not sure what's happening.
Thanks.
Re: Ragdoll Q.
Posted: Sun Jun 03, 2012 4:29 pm
by Norbo
In what way did it not work? Removing elements from the simulation using Space.Remove prevents them from having any effect on the simulation. If all the relevant components (Entity objects, AngularMotors, BallSocketJoints, and everything else) are removed, then there will be no more ragdoll.
Setting the references to null has no effect unless you're trying to make the objects edible by the garbage collector, but it's probably a good idea to keep the objects around for reuse instead of throwing them away.
Re: Ragdoll Q.
Posted: Sun Jun 03, 2012 6:24 pm
by ruggy
It removes them all fine now, the problem is the second time I create the ragdoll it doesn't work. The entities seem to be split and end up in a position away from my model. I just wanted to check I was doing it the correct way. I'll have to investigate. I'm removing all entities, motors and ballsockets from the space then later when going back to ragdoll I'm creating new ones and adding them to the space.
I'll try keeping them around and re adding them to the space on subsequent uses and see if that helps (tomorrow).
Thanks.
Re: Ragdoll Q.
Posted: Mon Jun 04, 2012 2:58 pm
by ruggy
Hi,
Ok, so first time the character dies I create all the ragdoll entities / motors / ballsockets. Player respaws I remove them all from the space, everything is fine. Second time they die I call the same code but it doesn't 'new' the entities, it just re-initialises them. The torso works but all the rest seem offset somehow, as if the ballsocketjoint isn't connecting them anymore (a guess). So I've tried to re-init everything as it would be the first time by setting the connectionsA/B and offsetA/B. Like this (I've got similar code like this for every entity, ballsocket and angular motor, just showing head to torso here so it's easy to read):
Code: Select all
if (m_BallSocketJointHeadToTorso == null)
m_BallSocketJointHeadToTorso = new BallSocketJoint(m_Torso, m_Head, m_Head.Position + new Vector3(0, -.9f*s, 0));
m_BallSocketJointHeadToTorso.ConnectionA = m_Torso;
m_BallSocketJointHeadToTorso.ConnectionB = m_Head;
m_BallSocketJointHeadToTorso.OffsetA = (m_Head.Position + new Vector3(0, -.9f*s, 0)) - m_Torso.Position;
m_BallSocketJointHeadToTorso.OffsetB = (m_Head.Position + new Vector3(0, -.9f*s, 0)) - m_Head.Position;
g.m_App.m_Space.Add(m_BallSocketJointHeadToTorso);
This is how it looks on first death, the bepu objects roughly match my model (just using rotations)
This how it looks on second death, the head an arms don't seem to be connected to the torso anymore?

Re: Ragdoll Q.
Posted: Mon Jun 04, 2012 3:18 pm
by Norbo
Is the character always in the same pose/orientation on death? The configuration appears to use a lot of fixed world space offsets which would not work if the character could be in different poses.
To simplify the work, try building a 'bind pose' ragdoll constraint configuration. Once there's a definitely-working joint configuration for the bind pose, just move the entity bones around to match the current pose of the character without touching the constraints. The joints do not need to be changed at all if they were configured to allow the range of motions that the character could die in. If the death configuration violates the constraints a little, the joints will fight back to get back into a valid state.
Re: Ragdoll Q.
Posted: Mon Jun 04, 2012 7:21 pm
by ruggy
Yeah when they die I return them to bindpose then re-position all the entites so that they match the bindpose (but with an extra world transform so they align with the characters current position).
As for the 'definitely-working joint configuration' - that describes pretty much exactly how I set it up to begin with.
I'll try some more thing, it looks like not trying to do my own re-init of the ballsocketjoints has helped quite a lot, now it's trying to work but the entities that were removed from the Space previously fly across the map to form the new ragdoll (the second death) and when they get there they sometimes don't fall into place correctly, causing the ragdoll to vibrate and spasm, seems to get worse each time. I'm setting their position when I want the ragdoll to reform, is there a way to make it immediate? Perhaps I need to clear some velocities?
Thanks for the help btw, much appreciated.
Re: Ragdoll Q.
Posted: Mon Jun 04, 2012 7:32 pm
by Norbo
it looks like not trying to do my own re-init of the ballsocketjoints has helped quite a lot
A little background explanation: all constraints operate on the relative state of the connected entities. That's why they need no reconfiguration and why only entities need to be moved.
I'm setting their position when I want the ragdoll to reform, is there a way to make it immediate?
Setting the Entity.Position field is a direct set and instant teleportation, so there is no delay. As long as the position is being set to the proper location, the entities should not have to fly across the map to satisfy the constraints. The orientation needs to be updated too to prevent a correction-seizure on resimulation.
Perhaps I need to clear some velocities?
Clearing the velocities would be wise if there are any left over from the previous simulation. Computing velocities from the animation on death is a nice way to add some fluidity to the conversion from animated to ragdoll.
Re: Ragdoll Q.
Posted: Tue Jun 05, 2012 11:00 am
by ruggy
Hey it's fixed! It was my fault, I was setting the position of the entities incorrectly. It only worked the first time because the character spawned at the origin. Doh! Works perfectly now everytime. Thanks Norbo for pointing me in the right direction!