In XNA / Farseer I have something like this:

Body body = BodyFactory.CreateRectangle(world, 1f, 2f, 1f);
FixtureFactory.AttachCircle(0.5f, 1f, body, new Vector2(0f, 1f));

I have been told that body.Position property is the center of the AABB of the Body. In this example it seems not to be so. When I do something like this to display the coordinates of the position I see that they are at the center of the rectangle created at the beginning:

BodyFactory.CreateCircle(world, 0.1f, 1f, Body.Position);
BodyFactory.CreateCircle(world, 0.1f, 1f, Body.WorldCenter);

The center of gravity seems also to be the same.
I need this for drawing my texture over the Body. The origin for drawing is then like this:

Vector2 Origin = new Vector2(Sprite.Width / 2, Sprite.Height / 2);

Am I doing something wrong or does the engine not recognize, that a circle fixture is attached to the rectangle? Is there any workaround?

  • \$\begingroup\$ Body positioning uses different units than pixels, something like kilos meter seconds, so you need to convert pixels to farseer units to position objects in your game, and then convert them back when you need to draw them on the screen. Use the default 1:64 ratio, otherwise there are performance issues. Check their documentation like here \$\endgroup\$
    – dimitris93
    Aug 4 '15 at 21:21
  • \$\begingroup\$ That's not the problem.... I convert the units before drawing! The behavior only occurs when attaching an fixture with offset (because then the center can't be the original one). \$\endgroup\$ Aug 5 '15 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.