Quick Joint question

Oct 3, 2008 at 9:47 PM
What's the best way to re-attach a joint (revolute) that's been disposed at an earlier time?

New joint?
Or is there a faster way?

Is there a way to maybe just disable a joint, so that it can be re-enabled later or something?

I ask this because when I set CollisionResponseEnabled to be false and IsStatic to be true for bodies connected by joints, XNA throws a huge error.
The only way I figure I can alternate CollisionResponseEnabled and IsStatic with bodies with joints is disposing the joint(s) and somehow re-attaching them after the CollisionResponseEnabled and IsStatic are both set back to accept collision in the physicsSimulator.

Any ideas?
Developer
Oct 3, 2008 at 10:29 PM
Mmmm, thats tricky. Can you give us an example of why your changing your bodies to static?
Oct 4, 2008 at 12:32 AM
Edited Oct 4, 2008 at 1:05 AM
I'm essentially turning a few bodies strung together by joints into a sensor temporarily, and then changing it back under certain conditions met by the sensor.
I changed the CollisionResponseEnabled and IsStatic to create that effect.
The problem is changing this series of bodies back to their original state, with joints back to where they were.

I think I'm just going to make new instances from the JointFactory. The problem with this is deciding exactly where to put the new joints, especially if the rotation of the bodies are different than normal.
Oh well.
Coordinator
Oct 4, 2008 at 5:13 PM
"Is there a way to maybe just disable a joint, so that it can be re-enabled later or something?"

Yes there is, all springs and joints have an Enabled property on them.

"I ask this because when I set CollisionResponseEnabled to be false and IsStatic to be true for bodies connected by joints, XNA throws a huge error."

Could you write the error here so that I can see if it's Farseer Physics related?

From what you are trying to accomplish, I don't think that disposing the joints, and then recreating them is the best way.
Oct 4, 2008 at 9:12 PM
I just checked and Enabled is not on the method list for my joints.
Coordinator
Oct 4, 2008 at 9:28 PM
Edited Oct 4, 2008 at 9:33 PM
Damn it, my fault. I was looking at the 2.0 source and not 1.0.0.5.

Well, you could wait for 2.0 to be released or implement a Enabled property your self. Just insert a Enabled propery into Joint.cs and edit PhysicsSimulator.cs's "private void ApplyImpulses(float dt)" to replace this:

for (int i = 0; i < jointList.Count; i++)
{
    jointList[i].PreStep(inverseDt);
}

to be this:

for (int i = 0; i < jointList.Count; i++)
{
    if (jointList[i].Enabled)
    {
       jointList[i].PreStep(inverseDt);
    }
}

remember to do the same a few lines down where jointList[i].Update(inverseDt); is called
Developer
Oct 4, 2008 at 9:28 PM
What version of Farseer are you using? Try using the latest release.
Coordinator
Oct 4, 2008 at 9:29 PM
Hehe, beat you to it. I will send you an email in 2 seconds ;) Early warning.
Developer
Oct 4, 2008 at 9:32 PM
Damn, good timing. I had just looked that up too.