views:

258

answers:

3

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?

+1  A: 

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

eeeeaaii
Could not test it yet, but doesn that really freeze the object it it's in midair? (And, well, keep it there?)
Markus
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
Then the question is: How do I turn off gravity for a specific object (in Bullet)?
Markus
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
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
The idea was right, disabling gravity led to the solution. Staffan pointed out the function to use. Thanks alot to you, too!
Markus
+2  A: 

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
This is it! One has to take care of deactivation after collisions etc., but it works! Perfect! Thanks alot!
Markus
A: 

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.

nonVirtualThunk