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
How to: Locking body in place temporarily?
-
- Posts: 169
- Joined: Sun Jan 14, 2007 7:56 pm
- Location: Norway
Re: How to: Locking body in place temporarily?
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
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
-
- Posts: 19
- Joined: Thu Nov 27, 2008 1:44 pm
Re: How to: Locking body in place temporarily?
Thanks! Will try right away!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.
Whoops! I am sure mods will move it though. Sorry for the trouble!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