Edit the mass

General discussion about the R.U.B.E editor
Post Reply
dobruny.developeruch
Posts: 3
Joined: Wed Feb 27, 2013 1:28 pm

Edit the mass

Post by dobruny.developeruch »

How I can edit the mass?
Attachments
editMass.png
editMass.png (238.9 KiB) Viewed 8268 times
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Edit the mass

Post 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.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Edit the mass

Post 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);
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Edit the mass

Post by iforce2d »

Mass has been added in the properties panel as a first-class member of bodies in v1.3.
Post Reply