Hi,
I'm getting a strange result when I set a rigid body's mass to a value greater than about 12 (or 12.3534, to be more exact!) and apply an initial upwards velocity: after a few simulation steps, the object just gets stuck at the same position (in "mid-air"), with a velocity of 0. I wondered if anyone else has seen this?
It doesn't happen if I set the mass during the creation of the rigid body, which I realise is the proper way to do things; however, I'm a little concerned as I will need to be able to support switching rigid bodies between dynamic and kinematic states, which will require re-setting the mass (as discussed in this topic: http://tinyurl.com/83agdm - unless I work around it by re-creating the object, though that seems kinda clunky to me).
I've attached a simple program to demonstrate the problem; it's essentially copied from the "Hello World" demo, with the addition of the following code after rigid body creation/adding to the world:
// now set the mass to a higher value
mass = 12.3534;
rb->getCollisionShape()->calculateLocalInertia(mass, localInertia);
rb->setMassProps(mass, localInertia);
rb->updateInertiaTensor();
// add an upwards initial velocity
btVector3 vel(0.0, 1.0, 0.0);
rb->setLinearVelocity(vel);
When I run it, it's fine until the 135th simulation step:
...
i = 132, rb position: 0 0.238125 0, velocity: 0 -0.773519 0
i = 133, rb position: 0 0.225012 0, velocity: 0 -0.786754 0
i = 134, rb position: 0 0.211679 0, velocity: 0 -0.799989 0
i = 135, rb position: 0 0.211679 0, velocity: 0 0 0
i = 136, rb position: 0 0.211679 0, velocity: 0 0 0
i = 137, rb position: 0 0.211679 0, velocity: 0 0 0
... etc.
Maybe I've missed something out in resetting the mass? It just seems odd that it works up to a certain point, then stops...
Thanks,
Kate
P.S. Sorry if this has been posted previously; I've only recently started using Bullet and following the forum.
P.P.S. The attachment is just a text file - I had to add the .zip so it would let me upload it!!
Rigid bodies get stuck when setting mass > 12 after creation
-
- Posts: 41
- Joined: Thu Jan 08, 2009 11:20 am
- Location: London, UK
Rigid bodies get stuck when setting mass > 12 after creation
You do not have the required permissions to view the files attached to this post.
-
- Posts: 169
- Joined: Sun Jan 14, 2007 7:56 pm
- Location: Norway
Re: Rigid bodies get stuck when setting mass > 12 after creation
To me it seems like your rigid body is falling asleep (automatically deactivated) due to a low velocity. Can you try to disable deactivation on that rigidbody and see if that helps?
body->setActivationState(DISABLE_DEACTIVATION);
The default linear threshold for sleeping is 0.8, so your velocity is lower than that. You can also set the threshold to something else (lower), instead of disabling it completely: body->setSleepingThresholds(btScalar linear,btScalar angular)
Best regards,
Ola
body->setActivationState(DISABLE_DEACTIVATION);
The default linear threshold for sleeping is 0.8, so your velocity is lower than that. You can also set the threshold to something else (lower), instead of disabling it completely: body->setSleepingThresholds(btScalar linear,btScalar angular)
Best regards,
Ola
-
- Posts: 229
- Joined: Sun Sep 30, 2007 7:58 am
Re: Rigid bodies get stuck when setting mass > 12 after creation
Hi,
you also have to remove the body from the simulation before you can change the mass property. Then you can add it again.
you also have to remove the body from the simulation before you can change the mass property. Then you can add it again.
-
- Posts: 41
- Joined: Thu Jan 08, 2009 11:20 am
- Location: London, UK
Re: Rigid bodies get stuck when setting mass > 12 after creation
Hi Ola,
Yeah, that fixed it, thanks... I guess I should have thought of that, I just didn't expect it to deactivate mid-fall! I think I'll reset the threshold; 0.8 seems kinda high to me
K.
Yeah, that fixed it, thanks... I guess I should have thought of that, I just didn't expect it to deactivate mid-fall! I think I'll reset the threshold; 0.8 seems kinda high to me
K.