Moving rigid bodies for a ragdoll

DestroyerOfCities
Posts: 20
Joined: Fri Dec 10, 2010 3:39 am

Moving rigid bodies for a ragdoll

Post by DestroyerOfCities »

I have a ragdoll setup that integrates with my skinning implementation, such that the "ragdoll" is a bunch of capsule shapes with constraints that I use to update my bone positions/rotations. I only want the character to go into the "ragdoll" state on specific events, so I don't really want to drag the capsules around all the time. I also don't want to create all the capsule shapes when it's time to ragdoll, as I expect to go in and out of that mode repeatedly. Essentially, when I determine that it's time to go into ragdoll mode, I want to move all the capsule shapes to the current locations of the bones and then activate them.

I've followed this advice on how to enable/disable the capsule shapes. This works well, in that I can throw boxes through the character when the shapes are "disabled", and can then enable them and see the ragdoll work as expected. I can't, however, move the character and get the capsule shapes to move to the correct location. I've tried all manner of rigidBody::setWorldTransform, rigidBody::getMotionState::setWorldTransform, etc. But the shapes always seem to wind up at a different location than I'd expect. I don't know if perhaps there's a scale being applied, since my capsule shapes are all variously different sizes...?

Can anyone give me some advice on this? Is that technique of creating a btOverlapFilterCallback the right way of "disabling" the capsules? And how, given a world-space position and orientation, can I move the deactivated rigid bodies to match the bones?
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Re: Moving rigid bodies for a ragdoll

Post by benelot »

Fixing issues with positioning of physics and graphics can usually be debugged better by using a DebugDrawer. By that you can see were the shapes end up when you position them. To your question, there is no scaling applied, the rigidbody's COM is placed at your position, but maybe you do no clear velocities and forces or similar. We need a bit more insight here I think.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Moving rigid bodies for a ragdoll

Post by drleviathan »

I would expect slamming the transforms of the bones to just work when done correctly. If you're 100% sure you got the transforms right then the only (less likely) idea I have is that maybe the final transforms nevertheless subtly violate the system of constraints and the collection rapidly snaps to an unexpected configuration in a single step.
DestroyerOfCities
Posts: 20
Joined: Fri Dec 10, 2010 3:39 am

Re: Moving rigid bodies for a ragdoll

Post by DestroyerOfCities »

Yeah I was messed up in how I was drawing the mesh (effectively doubling the model matrix), when I turned on my own "debug shapes" stuff I could see that the capsules were where I expected them to be. :oops:

But now I have two additional questions. If I move the transforms and don't call activate(true) on the rigidBodies, they don't actually move until I hit them with something. If I do call activate(true) on them, they move to the correct location, but it seems like the constraints all bunch up on one another in the first moment and then relax into their normal positions (as the ragdoll falls to the floor).