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

Binding two bodies

Topics: Developer Forum, User Forum
Aug 20, 2014 at 7:04 PM
Hey there

Despite the several hours I've spent trying to figure it out, I have been unable to figure out how I'd bind two bodies together, so that I can make something like a body and a head.

All I need is for two bodies to both influence eachothers physics properties, so that Body_A will always be XY away from Body_B, in a given direction. And when Body_A rotates, Body_B follows in relation to Body_A.

I'm pretty sure it's very simple, but I can't seem to figure it out. Any help?

Aug 21, 2014 at 4:05 AM
Edited Aug 21, 2014 at 4:07 AM
Hi Falgantil,

It's been a while since I've used Farseer. I've moved away from XNA to Cocos2d-X. Look at Joints. There are 3-4 different types of joints, if Farseer still closely follows Box2D Physics. What you are trying to do can be achieved using Joints.

b2World class should have create Joint methods. You should be able to create your b2Body then using the static create joint method(s) you should be able to attach the two bodies. When creating the joint, look at the overloaded methods to see how to put constraints to Body A and B.

When I was developing using Farseer, I used to reference both Box2D and Farseer documentation, as well as just digging through the class files to see what the methods were doing. The documentation is crappy for both physics engines.

Here are some of the classes that you should familarize yourself. You will use them extensively:
b2World, b2Body, b2Shape, b2Fixture, and b2ContactListener (checking collision detection)
Aug 21, 2014 at 12:55 PM
Hi macgeek911

I've tried to connect two bodies using the JointFactory tool, and none of the factory methods I've used has worked the way I need it to.
Some of them has completely rooted my model, and other has not modified anything at all.

Got any sample code which accomplishes just this?