drleviathan wrote:You should be doing somthing this:
Code: Select all
btTransform transform = object->getWorldTransform();
btVector3 position = transform.getOrigin();
transform.setOrigin(position + btVector3(0, 50, 0));
object->setWorldTransform(transform)
I think translate will make the object move more 'physically like'.
And I just found out that we can also use applyForce() to move the ball (the force has to be big like 1000)
Code: Select all
body->applyForce(btVector3(0, 1000, 0), btVector3(0, 50, 0));
drleviathan wrote:
Also, you probably want to activate the ball whenever you move it, just in case it has deactivated. Otherwise it might move to the new location but not fall.
Thank drleviathan, it works, the method activate() for the rigid body is the answer
Code: Select all
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[1];/*0 is the ground, 1 is the ball*/
btRigidBody* body = btRigidBody::upcast(obj);
/*This will try to move the ball up,
but only work when the ball is falling, not when it's on the ground*/
body->translate(btVector3(0, 50, 0));
/*After add this code, the ball can be moved up when it's on the ground*/
body->activate();