Bullet physics engine, how to freeze an object?
Asked Answered
S

6

17

Using Bullet 2.76 I'm trying to freeze an object (rigid body) so that it instantly stops moving, but still responds to collisions.

I tried setting it's activation state to DISABLE_SIMULATION, but then it's virtually nonexistent to other objects. Furthermore, if objects "collide" with it when it's disabled, strange things begin to happen (object's falling through static bodies, etc.)

I suppose, temporarily converting it to a static rigid body could work, but is there an existing "native" way to achieve this on Bullet's side?

Edit: Is there a way to turn off gravity for a specific object?

Sheryllshetland answered 10/6, 2010 at 13:52 Comment(0)
B
9

The documentation is a bit lacking but one would assume that the method below could be used to disable gravity on a specific body:

void btRigidBody::setGravity(const btVector3 &acceleration)
Belen answered 7/7, 2010 at 1:55 Comment(1)
This is it! One has to take care of deactivation after collisions etc., but it works! Perfect! Thanks alot!Sheryllshetland
Q
9

Just set rigid body's mass to 0, then it become static...

http://bullet.googlecode.com/svn/trunk/Demos/HelloWorld/HelloWorld.cpp

Quadrangle answered 18/2, 2013 at 11:15 Comment(2)
The link is dead now.Sheryllshetland
here is a new link: github.com/bulletphysics/bullet3/blob/master/examples/… setting mass to 0 didn't work for me though.Monosome
V
6

There are functions for btRigidBody called setLinearFactor(x,y,z) and setAngularFactor(x,y,z) that allow you to limit motion along a specific axis and rotation about a specific axis respectively. Calling both functions with all 0's as arguments should stop all motion. Calling them again with all 1's will allow motion again.

Valles answered 14/10, 2010 at 0:50 Comment(0)
T
5

Set the activation state to zero. This is what happens when the object sleeps naturally. Gravity and so forth will not take effect until it is woken again.

rigidBody->setActivationState(0);

Then just like any sleeping object, it will be woken on a collision or if you apply a force to it.

Timeconsuming answered 25/5, 2013 at 15:44 Comment(3)
then, how do you wake it?Incondite
@Incondite Apply a force, either directly or through a collision.Timeconsuming
this means also we could make it sleep on air? also, unfortunately this seems not exposed at JMonkeyEngine bullet wrapperPadauk
C
3

For this method to stop your actor you must call this every update frame.

void StopActor()
{
    m_pRigidBody->setLinearVelocity(btVector3(0,0,0));
}
Cupo answered 13/9, 2011 at 1:36 Comment(0)
S
1

set the velocity and momentum to zero and set the mass to a really, really large number.

Soidisant answered 15/6, 2010 at 12:55 Comment(6)
Could not test it yet, but doesn that really freeze the object it it's in midair? (And, well, keep it there?)Sheryllshetland
It does if you are using the real equations for gravity: F = G * (m1 * m2) / r^2 However most engines would not use this equation and would just assume constant gravity ( F = m * g ) so you would have to also turn off gravity and any other constant forces for this object. However this should work for any elastic forces and for your collision engine (which probably uses elastic forces).Soidisant
Then the question is: How do I turn off gravity for a specific object (in Bullet)?Sheryllshetland
sorry most of my experience is in building physics engines but I do not have specific experience with Bullet. Can you specify which forces apply to which objects/bodies? Is there a configuration file or something?Soidisant
I was curious so I read some documentation on Bullet. It doesn't look like they make it easy to modify the forces. It might be easier to change the type of your object to static.Soidisant
The idea was right, disabling gravity led to the solution. Staffan pointed out the function to use. Thanks alot to you, too!Sheryllshetland

© 2022 - 2024 — McMap. All rights reserved.