Changing the mass from 0.0f to any other value.

User avatar
dotsquid
Posts: 22
Joined: Fri Jan 14, 2011 7:10 pm
Location: Ukraine

Changing the mass from 0.0f to any other value.

Post by dotsquid »

Hi.

The problem is that if I change the mass of the rigid body from zero (the initial mass) to any other value the rigid body stays static (despite isStaticObject() returns false). Activating the body doesn't help (although isActive() returns true). Apply the force doesn't move the body, gravity doesn't affect it either.
If I create a rigid body with the positive mass I can freely change it to zero and back and forth again.

How to overcome this problem? Thanks in advance.
Kanttori
Posts: 38
Joined: Thu Jul 08, 2010 12:52 am

Re: Changing the mass from 0.0f to any other value.

Post by Kanttori »

Hi,

Sounds familiar, I think the problem is that the object stays in the "static list" even if the mass gets changed. You can fix this by removing the object from the dynamicsworld and then adding it back again..
User avatar
dotsquid
Posts: 22
Joined: Fri Jan 14, 2011 7:10 pm
Location: Ukraine

Re: Changing the mass from 0.0f to any other value.

Post by dotsquid »

Thanks for the reply.
Well, it's not the best solution, because this operation takes some time (maybe it's negligible but anyway).
So I wonder is it a bug or a normal behaviour?
Kanttori
Posts: 38
Joined: Thu Jul 08, 2010 12:52 am

Re: Changing the mass from 0.0f to any other value.

Post by Kanttori »

Not sure if it's a bug or not, haven't really looked at the code other than to solve it to that point. Generally speaking rigidbodies don't really "know" anything of the things that use them so having the setmass do something wouldn't work. Anyway, something like remove+add back would probably have to happen internally if the mass was checked for, but then this check would have to be done per rb per simulation step I guess.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Changing the mass from 0.0f to any other value.

Post by Erwin Coumans »

You need to remove a rigid body from the world, before changing the mass (or shape etc), and then re-insert it. This way, the internal structures will be properly updated.

Thanks,
Erwin
User avatar
dotsquid
Posts: 22
Joined: Fri Jan 14, 2011 7:10 pm
Location: Ukraine

Re: Changing the mass from 0.0f to any other value.

Post by dotsquid »

Kanttori, Erwin
thank you for your replies.