I have asked this question couple days ago. I thought I fixed the issue since I don't keep my program on the moment I start it but I found something I can't fix.
Here is the scenario:
- I have a sphere object thats centered at (0.0, 2.0, -5.0). It has a 1KG mass and has a Sphere Collision Shape with zero radius.
- The world gravity force is (0,0,0). I know for a fact that the object is just "sitting in the emptiness"
- There are three input events I attach to my object: if I press 'W' the rigid body's linear velocity is set to (0.0,0.0,-10.0);
- I added a "profiler" to check out the position and linear velocity of the object every frame, and linear velocity during key press.????
- ?For each frame it prints "ID. posX posY posZ LinearVelocityX LinearVelocityY LinearVelocityZ" (ID is for keeping count)
- For each input event it prints "new velocity: LinearVelocityX, LinearVelocityY, LinearVelocityZ"
The problem:
When I constantly move the object, there is no problem; everything works fine. However, the object doesn't move if I keep it idle for around 5 seconds or more.
The test and results:
I run the program. Wait for 5 seconds and then press "W" the linear velocity gets zeroed out after the simulation step even if the linear velocity was set during the event firing:
240. 0 2 -5 0 0 0
241. 0 2 -5 0 0 0
242. 0 2 -5 0 0 0
new velocity: 0, 0, -10
243. 0 2 -5 0 0 0
244. 0 2 -5 0 0 0
245. 0 2 -5 0 0 0
246. 0 2 -5 0 0 0
247. 0 2 -5 0 0 0
The code:
Physics system update:
void BulletPhysicsSystem::update(double dt) {
mWorld->stepSimulation(1/60.0f,5);
//This is the profiling
btTransform transform; btVector3 v(mComponents[0]->mRigidBody->getLinearVelocity());
mComponents[0]->mRigidBody->getMotionState()->getWorldTransform(transform);
std::cout << ++i << ". " << transform.getOrigin().x() << " " << transform.getOrigin().y() << " " <<transform.getOrigin().z() << " ";
std::cout << v.x() << " " << v.y() << " " << v.z() << "\n";
}
Main loop:
sf::Clock clock;
while(mRunning) {
mCurrentState->processInput();
mCurrentState->update(clock.getElapsedTime().asSeconds());
//This function updates the physics
mRenderWindow.clear(); mRenderWindow.pushGLStates();
mCurrentState->render(); mRenderWindow.popGLStates(); clock.restart(); mRenderWindow.display();
}
A video from my scene with the problem in it:
Additional notes:
The input and Graphics works in my system which gets the position from the rigid body of the bullet physics component. But from what I see that the problem is in my time step but I don't know how to fix it. Even a fixed time step doesn't seem to show a result that at least moves the object. What am I doing wrong?
I am so desperate to fix this issue. If any more information is needed please tell me.
Thanks,
Gasim