Page 1 of 1

Can't Move rigid body / Apply force

Posted: Fri Dec 02, 2011 1:02 am
by Alundra
Hi,
I have bullet correctly initialized and have 200 sphere who collide, all works fine but when i want apply force to a rigid body he doesn't do anything or if i use translate( vec3 ) on a simple sphere on a plane, he moves but don't update his position with gravity.

Do I have forget something ?
Thanks for help

Re: Can't Move rigid body / Apply force

Posted: Sat Dec 03, 2011 4:13 pm
by Dr.Shepherd
Alundra wrote:Hi,
I have bullet correctly initialized and have 200 sphere who collide, all works fine but when i want apply force to a rigid body he doesn't do anything or if i use translate( vec3 ) on a simple sphere on a plane, he moves but don't update his position with gravity.

Do I have forget something ?
Thanks for help
Too little information, either you paste your code here, or describe your problem more clearly.

There may be problem with your initialization of rigid bodies, or the force is not applied correctly.

Re: Can't Move rigid body / Apply force

Posted: Mon Dec 05, 2011 2:10 pm
by Alundra
Here the bullet code I use to create a world, static plane and a ball :

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.0f,-9.81f,0.0f));

plane_shape = new btStaticPlaneShape( btVector3( 0.0f, 1.0f, 0.0f ), 0.0f );
plane_body = new btRigidBody( 0.0, new btDefaultMotionState, plane_shape, btVector3( 0.0f, 0.0f, 0.0f ) );
dynamicsWorld->addRigidBody( plane_body );

ball_shape = new btSphereShape(1.0);
ball_body = new btRigidBody( 10.0f, new btDefaultMotionState, ball_shape, btVector3( 5.0f, 5.0f, 5.0f ) );
ball_body->translate( btVector3( 0.0f, 10.0f, 0.0f ) );
dynamicsWorld->addRigidBody( ball_body );
Here the code I use to Update the simulation and translate the sphere :

Code: Select all

if( IsKeyDown( Key::F ) )
  ball_body->translate( btVector3( 0.0f, 5.0f, 0.0f ) );

dynamicsWorld->stepSimulation( Elapsed, 10 );
Problem : The ball translate "Y += 5.0f", but don't update its position with gravity, it stay static.
Goal : I would manage all movement by bullet : translation, rotation, force ... Is it possible ?

Thanks for the help

EDIT :

The ball update with gravity using :

Code: Select all

dynamicsWorld->stepSimulation( 1.0f / 60.0f, 10 );
But I've got some case when the ball stay static and never update its position again with gravity.
Is it normal I must use 1/60 to get it to work ?

Using this code the ball doesn't move :

Code: Select all

ball_body->applyForce( btVector3( 10.0f, 0.0f, 0.0f ), btVector3( 0.0f, 0.0f, 0.0f ) );
Maybe i don't set correctly the force ?

Re: Can't Move rigid body / Apply force

Posted: Mon Dec 05, 2011 4:21 pm
by Dr.Shepherd

Code: Select all

btDynamicsWorld::stepSimulation( btScalar timeStep,   int maxSubSteps=1,   btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
If you pass a very large timeStep as the first parameter [say, five times the size of the fixed internal time step], then you must increase the number of maxSubSteps to compensate for this, otherwise your simulation is “losing” time.

In your code, the first variable is "elapsed", it should be the root of the problem. You maybe made a mistake in the unit. (seconds/milliseconds)

check out this tutorial article:
http://bulletphysics.org/mediawiki-1.5. ... _the_World