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

Rotating a body around another body.

Topics: Developer Forum, User Forum
Dec 12, 2010 at 11:24 PM

I am trying to rotate one body around another body by an angle that I determine from the mouse cursor's position in relation to the body I want to rotate around (when the mouse button is pressed).

float rotation = (float)Math.Atan2(mousePos.Y - bodyCenter.Y, mousePos.X - bodyCenter.X);

I'm using a revolutejoint to connect the two bodies and setting the rotating body's rotation equal to the value above. However, I am wondering if there is a better way of doing this as I understand it's pretty bad to alter the rotation manually, and I'm also having the problem that when I connect the two bodies using the revolutejoint, the mass of one body adds to the other.

Any suggestions?

Dec 20, 2010 at 8:36 PM

I'm not sure how bad it really is. I change rotation on my latest project and I have no issues yet :)

Dec 21, 2010 at 2:46 AM

If you are using Farseer Physics Engine 3.0 or newer, changing the rotation of an object is actually quite safe as we look for new contacts on each change in rotation. This gives us a pretty realistic behavior, but it is still better to use torque.

Have in mind that because we want the rotation to be realistic and search for new contacts on each change in rotation, it can be quite expensive to rotate a body manually. For performance reasons I would recommend you use SetTransformIgnoreContacts() if you don't need to find new contacts on each change in rotation.