How to: Locking body in place temporarily?

devmelon
Posts: 19
Joined: Thu Nov 27, 2008 1:44 pm

How to: Locking body in place temporarily?

Post by devmelon »

Hi, I need help figuring out how I should lock a body in place (and later unlock it) using bullet.

I have a rigid body in my world with a hinge constraint applied to it, to allow angular rotation. Now I also would like to lock it (freeze it in place) until I unlock it, so other objects should still collide with it, but it should not move anywhere. Should I use constraints or other means to achieve this? Please take a moment and explain if you would like, as I have a hard time understanding constraints.

What I am trying to achieve here is the effect of having a lock on a door. In game, when user presses a button, door is supposed to unlock.

Thanks,
devmelon
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Re: How to: Locking body in place temporarily?

Post by ola »

When you want a locked body, add it to the physics world as a static object (set the mass and inertia to zero, store the real mass properties somewhere for later).

When you want to unlock, remove it from the physics world, re-set the mass properties, and add it back. Back to locked: remove from physics world, set mass to zero, add back. And so on. It's as easy as that.

Best regards,
Ola

ps: you should post in the Bullet-specific forum, not this general one. http://www.bulletphysics.com/Bullet/php ... um.php?f=9
devmelon
Posts: 19
Joined: Thu Nov 27, 2008 1:44 pm

Re: How to: Locking body in place temporarily?

Post by devmelon »

ola wrote:When you want a locked body, add it to the physics world as a static object (set the mass and inertia to zero, store the real mass properties somewhere for later).

When you want to unlock, remove it from the physics world, re-set the mass properties, and add it back. Back to locked: remove from physics world, set mass to zero, add back. And so on. It's as easy as that.
Thanks! Will try right away!
ola wrote:ps: you should post in the Bullet-specific forum, not this general one. http://www.bulletphysics.com/Bullet/php ... um.php?f=9
Whoops! I am sure mods will move it though. Sorry for the trouble! :)