When should I apply forces to my rigid bodies?

Post Reply
piku
Posts: 3
Joined: Thu Feb 16, 2012 2:54 pm

When should I apply forces to my rigid bodies?

Post by piku »

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()?
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm
Contact:

Re: When should I apply forces to my rigid bodies?

Post by dphil »

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

Code: Select all

rigidBody->activate(true);
after your force application if you are not already doing so.
piku
Posts: 3
Joined: Thu Feb 16, 2012 2:54 pm

Re: When should I apply forces to my rigid bodies?

Post by piku »

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. Call

Code: Select all

rigidBody->activate(true);
after your force application if you are not already doing so.
Ahh I was only calling that once at the start.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm
Contact:

Re: When should I apply forces to my rigid bodies?

Post by dphil »

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:

Code: Select all

rigidBody->setActivationState(DISABLE_DEACTIVATION);
in which case you never need to manually activate it.
Post Reply