Question

I have created a platformer game using farseer physics with a player and some objects etc but are having some problem with mass on objects.

The player is composed by a wheel and a torso connected with a joint and everything works almost perfectly when not setting mass on any object. But not using mass creates an unstable simulation because when changing texture on an object, the mass increase or decrease strangely. But when assigning a correct mass and density nothing works as it is supposed to and I don't know why. I increase force and such to correspond to the new weight on stuff but when moving the player he slides back and forth and kind of bounce sideways when stopping. And when picking up an object he hacks all over the screen.

So does anyone know a solution cause I'm stuck?

The only thing I have found so far is that the mass of a body in farseer physics is calculated by the density of its fixtures. Hence the weight increase/decrease when changing texture. But I can't get it to work when manually assigning a weight.

Was it helpful?

Solution

Taken from the Box2D Manual:

The fixture density is used to compute the mass properties of the parent body. The density can be zero or positive. You should generally use similar densities for all your fixtures. This will improve stacking stability.

The mass of a body is not adjusted when you set the density. You must call ResetMassData for this to occur.

fixture->SetDensity(5.0f);    
body->ResetMassData();

You may need to Reset the mass data in order for it to work properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top