This project has moved. For the latest updates, please go here.

Slow joint response

Topics: User Forum
Feb 22, 2011 at 10:14 PM
Edited Feb 22, 2011 at 10:21 PM

In my project I have an object that sticks to another object when they collide and there after they should stay together and maintain the same angle.

the main body rotates based upon the mouse position. and the secondary body gets its angle and position through a joint between the two.

My first attempt was using a weld joint which does an excellant job at keeping them in the correct locations however when the main body is rotated by the mouse, the secondary body is slow to respond

this manifests its self in the form of a "flex" in the weld joint.

so to counter this i attempted to add an angle joint as well, which appeared to have no effect. so I commented out the code for creating the weld to make sure the angle was working and I found that as

the primary body rotates the secondary does also rotate but is sluggish in its responses.

My question is: is there a way to make the angle joint respond immediatly, and/or prevent the weld joint from flexing when rotation is applied to on of the bodies?

In asking this question the thought comes that it may be due to the mass or density of the objects. this is currently set to 0.01f I don't know if that's too high or what would normally be an optimal density.

In advance I would like to thank you all for the help. you have all been quite patient with me in my learning this great physics engine.


EDIT: I also thought I should mention that I am applying the rotation by getting an angle of the mouse relative to the fixture position and then setting fixture.body.rotation equal to that angle.

Feb 23, 2011 at 7:18 AM

As Farseer uses an iterative solver joints (even the weld joint) will never be 100% rigid. That said your joints indeed seem to react too slow. First thing that comes to mind is that Farseer does not like it when you manipulate objects directly. So changing the rotation by using body.ApplyTorque or body.ApplyAngularImpulse would probably yield better results. Calculating the correct impulse for a certain angle is not trivial though and will need some finetuning/experimenting.

Another thing you could try: When the two objects (A and B) collide clone the fixture(s) of object B and add them to body A, then destroy body B. If you want to separate the objects later just clone the fixture(s) you want to separate again and add them to a new body, afterwards remove them from body B. If you do it like that there won't be any lag between the two joined objects.

One last remark: If you mainly manipulate the object in question via direct user input (e.g. mouse etc.) consider making it kinematic instead of dynamic. Other dynamic objects will still collide with it. Kinematic bodies don't collide with static and other kinematic bodies however so that might produce problems elsewhere.

Feb 23, 2011 at 8:07 PM

Thank you for your response.

I'm interested in exploring further your second suggestion. In exploring your second suggestion.

My question: is there a better way to clone the fixture just using the createFixture and distroyFixture? or is there a more elegant way of doing it?

Feb 24, 2011 at 9:57 AM

Not for now unfortunately. But the next release will feature clone and deepclone methods for bodies, fixtures, and shapes. You can already have a look at it in the source. The feature is not yet tested thoroughly though.