Bullet physics engine, how to freeze an object?
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 开发者_StackOverflow社区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?
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)
Just set rigid body's mass to 0, then it become static...
http://bullet.googlecode.com/svn/trunk/Demos/HelloWorld/HelloWorld.cpp
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.
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.
For this method to stop your actor you must call this every update frame.
void StopActor()
{
m_pRigidBody->setLinearVelocity(btVector3(0,0,0));
}
set the velocity and momentum to zero and set the mass to a really, really large number.
精彩评论