Thank you so much for the help, I will try that and get back to you with the result!
Worked perfect! Thank you again. I just changed Vector2 localPos = bones.worldToLocal(worldPos);
to Vector2 localPos = bones.getParent().worldToLocal(worldPos);
And it now works for the whole rag doll! Didn't have to change the rotation or account for that the root bone has no parent..not sure why, but as long as it works I'm happy π
I was a bit quick to celebrate it turns out.. I didn't test the rotation properly..I got it working now though..If anyone is interested I changed the last two lines from:
bones[i].setRotation(bones[i].getParent().getWorldRotation() * MathUtils.radiansToDegrees);
bones[i].updateWorldTransform();
to:
bones[i].setRotation(ragDoll[i].getAngle() * MathUtils.radiansToDegrees - bones[i].getParent().getWorldRotation() );
skeleton.updateWorldTransform();
And now it seems to work for the whole ragdoll.
Cheers!
Hi again, I now ran into some troubles when I turn my character and flip the skeleton π
The bounding boxes of the skeleton seems to be unchanged after the flip..
I read this post which seems to be about the same thing:
viewtopic.php?f=9&t=2160
and concluded that the best way to go about it is to construct two ragdolls, one for each direction the skeleton is facing and to use the correct one.
To do this I tried to go through the vertices of the bounding boxes and inverting the x-coordinate when the skeleton is flipped as suggested by the post above:
BoundingBoxAttachment b = (BoundingBoxAttachment) itr.next();
float[] vertices = b.getVertices();
for(int p = 0; p < vertices.length; p+=2){
vertices[p] = -vertices[p];
}
// create box2d body from vertices
However this doesn't work and my box2d bodys are all messed up..Any ideas on how to get this to work?