I've got a space ship which I've created a btRigidBody for and now I want to make it user controllable. In my code I use applyCentralForce() and give it a vector representing the force. Sometimes this works perfectly, other times it doesn't appear to do anything. It doesn't do anything in that the ship remains still (I have the gravity vector set to (0,0,0) as I don't want gravity).
If I step through the code using a debugger the vector I want is passed into applyCentralForce() which does its calculation correctly, so from my limited understanding Bullet is being updated with the new force.
How am I supposed to use applyCentralForce? Can I just call it from within my application's loop, or should I be doing this inside a tick callback? I assume I should be doing this before calling stepSimulation()?
When should I apply forces to my rigid bodies?
Re: When should I apply forces to my rigid bodies?
During your main application loop should be fine, before or after calling Bullet's stepSimulation().
Objects can go to sleep if they are inactive for a period of time, meaning they need to be woken up to respond to manual forces. Call
after your force application if you are not already doing so.
Objects can go to sleep if they are inactive for a period of time, meaning they need to be woken up to respond to manual forces. Call
Code: Select all
rigidBody->activate(true);
Re: When should I apply forces to my rigid bodies?
Ahh I was only calling that once at the start.dphil wrote: Objects can go to sleep if they are inactive for a period of time, meaning they need to be woken up to respond to manual forces. Callafter your force application if you are not already doing so.Code: Select all
rigidBody->activate(true);
Re: When should I apply forces to my rigid bodies?
Alternatively, if you know your object will always be in motion (or if any performance you might gain from sleeping is unimportant to you), then if you want you could just turn off the sleep behaviour altogether when the body is created:
in which case you never need to manually activate it.
Code: Select all
rigidBody->setActivationState(DISABLE_DEACTIVATION);