Page 1 of 1

Edit the mass

Posted: Thu Feb 28, 2013 11:28 am
by dobruny.developeruch
How I can edit the mass?

Re: Edit the mass

Posted: Thu Feb 28, 2013 5:02 pm
by iforce2d
The mass of a body is determined by the density of the fixtures attached to it. One way to set the mass to a specific value is to scale the density of all fixtures equally.

Unfortunately there are no body::getMass or fixture::getDensity functions exposed to script at the moment, otherwise it would be quite easy to write a script to do this. I will add these functions in the next update.

Re: Edit the mass

Posted: Sun Mar 10, 2013 5:32 pm
by iforce2d
In v1.2 the script fixture class now has setDensity and setMass functions, and the body class also has a getMass and setMass functions, so this is now possible.

I kinda forgot about adding the mass as a first class property of bodies (to display and edit in the properties panel), but then again it's not actually a first class property of bodies anyway. Maybe this could be done in the next update.

In the meantime you could add a script like this to your action menu:

Code: Select all

float mass = queryNumericValue("Mass:");

body[] bodies = sb();
for (uint i = 0; i < bodies.length; i++) 
	bodies[i].setMass(mass);

Re: Edit the mass

Posted: Sun May 26, 2013 11:57 pm
by iforce2d
Mass has been added in the properties panel as a first-class member of bodies in v1.3.