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
Can't Move rigid body / Apply force
-
- Posts: 168
- Joined: Tue Jan 04, 2011 11:47 pm
Re: Can't Move rigid body / Apply force
Too little information, either you paste your code here, or describe your problem more clearly.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
There may be problem with your initialization of rigid bodies, or the force is not applied correctly.
-
- Posts: 14
- Joined: Sat Aug 13, 2011 3:25 pm
Re: Can't Move rigid body / Apply force
Here the bullet code I use to create a world, static plane and a ball :
Here the code I use to Update the simulation and translate the sphere :
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 :
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 :
Maybe i don't set correctly the force ?
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 );
Code: Select all
if( IsKeyDown( Key::F ) )
ball_body->translate( btVector3( 0.0f, 5.0f, 0.0f ) );
dynamicsWorld->stepSimulation( Elapsed, 10 );
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 );
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 ) );
-
- Posts: 168
- Joined: Tue Jan 04, 2011 11:47 pm
Re: Can't Move rigid body / Apply force
Code: Select all
btDynamicsWorld::stepSimulation( btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
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