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?

sunside
  • 8,069
  • 9
  • 51
  • 74

6 Answers6

9

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

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

miki
  • 91
  • 1
  • 1
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)
Staffan
  • 1,769
  • 13
  • 15
  • This is it! One has to take care of deactivation after collisions etc., but it works! Perfect! Thanks alot! – sunside Jul 19 '10 at 13:38
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.

MKroehnert
  • 3,637
  • 2
  • 34
  • 43
nonVirtualThunk
  • 2,842
  • 20
  • 20
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.

weston
  • 54,145
  • 21
  • 145
  • 203
3

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

void StopActor()
{
    m_pRigidBody->setLinearVelocity(btVector3(0,0,0));
}
jacobsgriffith
  • 1,448
  • 13
  • 18
1

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

eeeeaaii
  • 3,372
  • 5
  • 30
  • 36
  • Could not test it yet, but doesn that really freeze the object it it's in midair? (And, well, keep it there?) – sunside Jun 16 '10 at 11:24
  • 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). – eeeeaaii Jun 16 '10 at 16:34
  • Then the question is: How do I turn off gravity for a specific object (in Bullet)? – sunside Jun 17 '10 at 12:39
  • 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? – eeeeaaii Jun 18 '10 at 16:25
  • 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. – eeeeaaii Jun 18 '10 at 19:24
  • The idea was right, disabling gravity led to the solution. Staffan pointed out the function to use. Thanks alot to you, too! – sunside Jul 19 '10 at 13:40