applyForce stops working when btRigidBody does not move for some time
Posted: Tue Apr 03, 2018 7:41 pm
Hello,
I have a ground plane and one cube that I let fall down.
When the key "a" is pressed I apply a force thats direction is against gravity.
This works fine, as long as I press "a" the cube flies upwards, if I release "a" it falls down again.
But after a certain time applyForce() does not have any effect any more.
What I found during debugging is: In btRigidBody.c in applyDamping() I print out m_linearVelocity.
The values make sense. If the cube rests without movement then the values in m_linearVelocity go lower.
At a certain point they become 0.0 and at exact that time applyForce() does not have an effect any more.
If I then press "a" and by that do applyForce() then the values in m_linearVelocity go to a certain value,
but the cube does not move any more.
i have these global variables:
The initialization is done like this (gravity goes in direction Z):
To apply a force (each cycle this code is executed if "a" is pressed:
It would be great if anybody had a hint on this.
It looks to me that after some dampening it is detected that the velocity is near 0 and then it is set to 0.
Not sure if I need to do anything else.
Thanks for any hints,
Torsten
I have a ground plane and one cube that I let fall down.
When the key "a" is pressed I apply a force thats direction is against gravity.
This works fine, as long as I press "a" the cube flies upwards, if I release "a" it falls down again.
But after a certain time applyForce() does not have any effect any more.
What I found during debugging is: In btRigidBody.c in applyDamping() I print out m_linearVelocity.
The values make sense. If the cube rests without movement then the values in m_linearVelocity go lower.
At a certain point they become 0.0 and at exact that time applyForce() does not have an effect any more.
If I then press "a" and by that do applyForce() then the values in m_linearVelocity go to a certain value,
but the cube does not move any more.
i have these global variables:
Code: Select all
btBroadphaseInterface* broadphase;
btDefaultCollisionConfiguration* collisionConfiguration;
btCollisionDispatcher* dispatcher;
btSequentialImpulseConstraintSolver* solver;
btDiscreteDynamicsWorld* dynamicsWorld;
btCollisionShape* groundShape;
btDefaultMotionState* groundMotionState;
btRigidBody::btRigidBodyConstructionInfo* groundRigidBodyCI;
btRigidBody* groundRigidBody;
btCollisionShape* fallShape;
btDefaultMotionState* fallMotionState;
btRigidBody::btRigidBodyConstructionInfo* fallRigidBodyCI;
btRigidBody* fallRigidBody;
btVector3* fallInertia;
The initialization is done like this (gravity goes in direction Z):
Code: Select all
broadphase = new btDbvtBroadphase();
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0, 0, -10));
groundShape = new btStaticPlaneShape(btVector3(0, 0, 1), 1);
groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, -1)));
groundRigidBodyCI = new btRigidBody::btRigidBodyConstructionInfo(0, groundMotionState, groundShape, btVector3(0, 0, 0));
groundRigidBody = new btRigidBody(*groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
btScalar mass = 1;
fallShape = new btBoxShape(btVector3(0.5, 0.5, 0.5));
fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 15)));
fallInertia = new btVector3(0, 0, 0);
fallShape->calculateLocalInertia(mass, *fallInertia);
fallRigidBodyCI = new btRigidBody::btRigidBodyConstructionInfo(mass, fallMotionState, fallShape, *fallInertia);
fallRigidBody = new btRigidBody(*fallRigidBodyCI);
dynamicsWorld->addRigidBody(fallRigidBody);
Code: Select all
#define IMP 50
fallRigidBody->applyForce(btVector3(0, 0, IMP), btVector3(0, 0, 0));
It looks to me that after some dampening it is detected that the velocity is near 0 and then it is set to 0.
Not sure if I need to do anything else.
Thanks for any hints,
Torsten