Handle (as in move, reset, destroy) complex objects

Topics: Developer Forum
Nov 12, 2010 at 10:47 AM


here's another issue i am trying to wrap my head around. I am currently implementing different kinds of "player figures".

So in the current example you're free to choose between bike and ski for example.

First of all regarding a figure type alone. It consists of limbs, objects, joints etc etc.
Now of course i need to be able to create/delete/move/reset the player during runtime as needed.
What would be a good way to approach that ? I first simple moved the body all others are linked to in any way. But of
course this leads to explosions as the joints get stressed heh. Should i rather move all subbodies manually
with defined offsets ? Or should i create a helper function that moves the body fast instead of directly setting the new
position ?

And then regarding different player types. I was thinking if it makes sense to have a baseclass that implements
a skeleton with methods to Update (target angles based on mouse position parameters for example), Set position
(using  the result of the first question :P), create and delete all bodys/fixtures/shapes etc.

So basically i am wondering what is the best high level approach to design farseer based projects.

Just for fun here's what i've been doing so far while prototyping around and hacking some mechanics tests together:


Kind Regards,


Nov 13, 2010 at 4:41 AM

What I do when moving my player is calculate how far it has to move, then move all attached bodies by that amount. Like this.

void SetPosition(ref Vector2 pos)
	Vector2 offset = pos - _mainbody.Position;
	_mainbody.Position += offset;
	foreach (Body b in _attachedbodies)
		b.Position += offset;

And the same thing for rotation, too.

A baseclass for the player is a probably a good idea, as well as one for attached pieces, but that depends totally on your game and its needs. I'm also a fan of component-based programming, which is another possible way to go.

Nov 13, 2010 at 8:38 AM

Thanks a lot for the input robert!

Will also check out the link you gave.