Bullet physics undefined behavior with a dummy simulation

Started by
6 comments, last by ferrous 10 years, 4 months ago

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

Advertisement
Make sure its not caused by the object going into a sleeping state.

o3o

I can't believe this tongue.png I have been thinking the problem is with my timestep for the past 2 days. I want to know though. What is the advantage of having "inactive" objects?

I can't believe this tongue.png I have been thinking the problem is with my timestep for the past 2 days. I want to know though. What is the advantage of having "inactive" objects?

It lets you have more objects, as inactive objects aren't iterated over. Think of it like a LoD system or a culling system, but for physics. Just like in graphics, the fastest thing to do is not draw.

(That said, I find it a little weird that setting a velocity on an inactive object doesn't wake it up in the bullet engine -- at least for an object that wasn't actively put to sleep)

Isn't it generally considered a bad idea to explicitly set an objects velocity in a physics engine? I've always read that you should apply an appropriate force instead.

[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler

Isn't it generally considered a bad idea to explicitly set an objects velocity in a physics engine? I've always read that you should apply an appropriate force instead.

Generally, yes, but it depends on what you're trying to do.


Isn't it generally considered a bad idea to explicitly set an objects velocity in a physics engine? I've always read that you should apply an appropriate force instead.
I'd agree with that. Setting velocities directly always had repercussions on my systems. Dynamic objects are supposed to be completely simulated by the library, if you want to change them, at least make sure you wake em up from sleeping. Try calling ->activate().

Previously "Krohm"

Yeah, just a further tidbit, I had a game with cannons, and I wanted to be able to tweak the mass without effecting the velocity of the cannon ball, and I ended up still applying a force, and just including the mass into the calculation, so that the velocity would be constant as I messed with different masses.

This topic is closed to new replies.

Advertisement