This project has moved and is read-only. For the latest updates, please go here.

Rag-doll model

Topics: User Forum
Oct 15, 2008 at 12:31 PM
Hi, I'm new to the Farseer engine and have been looking desperately for a rag-doll code example. Do you know where can I find one? To join the parts seems quite easy using pins, but I find very difficult to animate the doll in a way that it moves over a surface. Or maybe should I use standard interpolation to move the model?

If you can give me any insight, it would be great!

Oct 15, 2008 at 2:30 PM
Edited Oct 15, 2008 at 2:32 PM
Hi, Welcome to the discussions. Hope you like Farseer Physics so far.

There have been some other requests on ragdolls here in the forums. I remember this and this one.

If you want a ragdoll seen from the side, you might wan't to contact Walaber. He made Gymnast with XNA and Farseer Physics, he might be able to send you the code.

If you manage to create a good ragdoll, would you mind letting me know? I have some plans on including a ragdoll sample in Farseer.
Oct 18, 2008 at 3:14 PM
Are you working with Silverlight?

If so, I just posted a RagDoll sample using the Physics Helper classes for Blend and Silverlight. These classes let you draw art out in Expression Blend and have them translated into Farseer Physics bodies and geometries automatically. (you can even draw out Joints!)

Here is a link to the RagDoll sample:

And to the blog post on Physics Helper:

I'll be moving this project to Codeplex in the next iteration, so if anyone is interested in helping out let me know!
Oct 18, 2008 at 5:55 PM
Very nice ragdoll Andy! He's kind of a fatty (Heavy guy ;) ) and has some problems with he's knees. (Bending the wrong way), but I really like him.

Have your thought about creating a codeplex project for this? I know you have your own website and all, but codeplex has source control, forums, bug reports and so on.

Anyways, I'll contact you in a moment. :)
Oct 18, 2008 at 6:26 PM
Yeah, I think I just need to give Min/Max angles to his joints to fix that "extra flexibility" in his knees and elbows.

I'm definitely moving to Codeplex. I was planning on waiting until the next iteration, but maybe I'll go ahead and do it sooner...
Oct 18, 2008 at 6:31 PM
I've taken a screenshot and made him my background. I call him crazy legs.
Do you think it's unwise to have such a relation to a ragdoll? hehe.

Back to topic:

Sounds great. Please tell me when you get your project up and running on CodePlex. I could add you as a related project on the frontpage.
I saw that you are using Johnathan Porter's boundary detection algorithm from Physics 2D, how is the performance?
Oct 18, 2008 at 7:21 PM
Ok, I had some time today to throw together the Codeplex site...

It would be great if you added it as a related project, thanks! And again - if anyone here is interested in contributing, please poke around a bit with the project, and let me know.

Yeah, I used a tweaked version of Johnathan Porter's algorithm to detect the outline of a Bitmap. I just adapted it a bit to work against UIElement's using Silverlight's VisualTreeHelper.FindElementsInHostCoordinates method (a HitTest). The truth is, I don't care about the performance so much (although it seems pretty good for what it has to do!) because I only use it on initialization to get the boundary points from a UIElement. I then hand those points off to Farseer to create a Polygon Geometry. So yeah, performance is good but it only adds to some "startup time" - doesn't affect the playtime response.

Oct 18, 2008 at 7:32 PM
That was quick.

Okay. In Farseer we need to focus a lot on performance since it's an iterative application. Even geometries created on the fly should be created fairly fast.

Anyways, Did you get my email?

I'll add you as a related project in a moment.

Oct 18, 2008 at 7:42 PM
Edited Oct 18, 2008 at 7:43 PM
Yeah, I hear you on the performance of dynamically added geometries. What I want to add to the Physics Helper is a way of caching the boundary outline points for any object. That way, the overhead of determining the outline is only taken as a one-time hit.

You can actually see the impact of the boundary detection in the Physics Helper demos... At the start of each demo there is a slight pause (especially noticeable in the Rag Doll demo). That pause is the boundary detection doing its thing and getting the points for the outline of each element.  But I think having a caching mechanism would make this a lot better.

I did get your email too, I'll respond to that next.
Oct 18, 2008 at 7:47 PM
I did not even notice the delay before.

I've only had a quick look at the code, did you implement the reduce method as in physics 2d or was it not necessary? I'm not very familiar with Silverlight and your implementation, so it might not be needed to reduce the amount of points.
Oct 18, 2008 at 8:05 PM
Oh, I can answer that question by my self :) Just noticed that you clean up the points in PhysicsSprite.xaml.cs.

You should play around with R# (Resharper 4.1). You have some unused code and some redundant code. Also, you can format XAML and C# in the editor by pressing CTRL + K + D. (format document)
Oct 19, 2008 at 1:05 AM
Yeah, definitely need some code cleanup in there. The result of several evenings of coding fun after a full day of work :)