In Farseer 3.3.1 for XNA, how do I change the origin of a Body? For example, when I create a Circle Body, instead of it rotating around its center, I want it to rotate around another specified point.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
I guess the revoulte joint is what you want. You can use it to pin the circle at a given position and the circle will rotate around that position.
Just to give a late answer to the question, answering what the question literally asks (for anyone who comes across it by searching):
You don't so much change the origin of a
Body as you place your
Fixtures relative to the body's origin (ie: in "Local" body space).
For example, assuming:
float radius = 1f; float density = 1f;
A centred circle would be this:
Body body = BodyFactory.CreateCircle(world, radius, density);
But a circle offset from the body origin by its radius would be:
Body b = BodyFactory.CreateBody(world); FixtureFactory.AttachCircle(radius, density, body, new Vector2(0, radius));
(Other shapes have similar offset parameters available. Raw polygons vertices are specified relative to the body's origin.)
Now, even if you do this, the centre of mass will still be at centre of the circle. If you want to move the centre of mass, you can do this:
body.LocalCenter = new Vector2(0, 0);
That is in the case where you've moved the circle centre away from the body's origin (as above), but you want to keep the centre of mass at the origin.
If you don't move the circle fixture, and just want to move the centre of mass, then do something like this:
body.LocalCenter = new Vector2(0, radius);
It is important to note, however, that Farseer normally recalculates the centre of mass! It does so if any of these things happen:
So if you do any of those things, you must set