Loose ragdoll joints

Topics: User Forum
Oct 18, 2009 at 11:30 PM

I'm currently working on a side-scroller and had been using my own mass-and-spring based ragdoll system until I decided to incoporate Farseer instead.

So far it's great, but I'm having some trouble keeping my ragdoll character together. I'm using a worldReference Vector2 variable to control the 'camera' in the game and when my ragdoll is created I'd like the camera to follow it as it falls through the level. The solution I've come up for with Farseer is this:

 

game.worldRef -= HeadBody.Position  - prevPosition;
HeadBody.Position = prevHeadPosition;

After each update, the difference in the head position (my root in the ragdoll) is subtracted from the worldRef, and then the head is moved back to its default position at center screen. This lets me take any forces applied to the head body and apply them to to the camera, which results in the camera following the ragdoll.

The problem is that while the head will stay centered, the other pieces of the ragdoll will not stay firmly attached to the head. They will eventually return to their attached position when the head stops moving, but at any kind of speed they look like they're being pulled apart.

Does anyone know if this is due to the joints themselves or is it some naive coding mistake on my part?

Cheers,
Owen 

 

 

Oct 20, 2009 at 4:21 PM

Let me know if I'm wrong, but it sounds like you're trying to keep the head fixed at a certain point in space and move everything else around it.  This does sorta break how the engine works.  For one, setting 'Position' should be avoided wherever possible.

The proper way would be to let the body fall freely, and then offset all the sprites in your drawing code based on where it is.  Rather than drawing sprites at (theBody.Position), it would be something along the lines of (theBody.Position - camera.Position + (<half of screen size to center things>)).

Oct 20, 2009 at 4:34 PM

Yes, that was what I was attempting to do. It's unfortunate that this breaks the engine.

Thank you very much for you help and I will try out your suggestion.

Oct 22, 2009 at 12:52 AM

Maybe look at fixed revolute joints and see if those work for you. Instead of moving the doll's head every frame, you can try moving the world position at which the doll's head is fixed to.