Objects do not react to forces after settling

mikejurka
Posts: 1
Joined: Fri Jun 19, 2009 9:50 pm

Objects do not react to forces after settling

Post by mikejurka »

I had a problem in my code but I can reproduce it with a slightly modified version of the Hello World example.

Essentially, it seems that after the cube in HelloWorld "settles", ie. has a velocity of 0, it will no longer react to gravity or impulses applied to it.

I essentially modified the simulation stepping code to run for more steps, and after 300 steps, which is when the cube has no longer been moving for quite a few steps, I apply an impulse. However, when I do this the position remains unchanged. Similarly, if I change the center of mass transform to put it above the floor, it remains stuck there; gravity doesn't do anything.

I'm relatively new to Bullet although already have a good part of an application written which uses Ogre with Bullet. However, I just ran into this problem and would appreciate any insights!

Code: Select all

// Modified chunk of AppHelloWorld.cpp
for (i=0;i<500;i++)
	{
		dynamicsWorld->stepSimulation(1.f/60.f,10);
    
    if (i == 300) {
      theDynamicRigidBody->applyCentralForce(btVector3(0, 100, 0));
    }
		
		printf("\n%d. step frame!!!\n", i);
		//print positions of all objects
		for (int j=dynamicsWorld->getNumCollisionObjects()-1; j>=0 ;j--)
		{
			btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[j];
			btRigidBody* body = btRigidBody::upcast(obj);
			if (body && body->getMotionState())
			{
				btTransform trans;
				body->getMotionState()->getWorldTransform(trans);
				printf("world pos = %f,%f,%f\n",float(trans.getOrigin().getX()),float(trans.getOrigin().getY()),float(trans.getOrigin().getZ()));
			}
		}
	}
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Objects do not react to forces after settling

Post by pico »

Hi,

the object felt asleep to save CPU. You can disable object sleeping. Or you can activate objects when you give them impulses.

see:
void btCollisionObject::activate(bool forceActivation)
void btCollisionObject::setActivationState(int newState)
TatamiSoftware
Posts: 10
Joined: Fri Dec 04, 2009 8:09 pm

Re: Objects do not react to forces after settling

Post by TatamiSoftware »

Thanks! I was stuck on this myself for a bit.