applyForce() wildly variable?

gfm
Posts: 16
Joined: Tue Sep 09, 2008 8:56 am

applyForce() wildly variable?

Post by gfm »

I've got a sphere floating in my world. Radius 0.2, mass 0.3. I've positioned it then set it to CF_KINEMATIC_OBJECT so it's floating.

The sphere floats there for a while, then I remove the CF_KINEMATIC_OBJECT flag, 0 the linear and angular velocities, call clearForces(), activate(true), then applyForce() with a force approximately a scale of about 300.

What I've found is that the "actual" force applied to the sphere is wildly variable. Sometimes the sphere will travel 130 units, other times only 30.

To get around this I'm instead calling setLinearVelocity() with a vector scaled around 50 and the distance the sphere travels only varies 2-3 units, stopping between 70-73 units.

While I would expect a little bit of non-determinism, I'm surprised by the amount of variance in the setLinearVelocity() case and totally perplexed by the variance in the applyForce() case.

What can be done to make bullet more deterministic?
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Re: applyForce() wildly variable?

Post by ola »

If the force you are applying is supposed to be a very short "bump" to the rigid body, you should apply an impulse instead. This will cause the same change in velocity every time. It's a good idea to look at the code in btRigidBody to see the difference.

The forces are integrated (with Euler integration) over the internal steps that bullet makes. So a force used as an impulse when applied from the "outside" will be dependent on your framrate -- sometimes bullet does 1 internal tick, sometimes none, sometimes many. You should rather use forces when they are applied over a longer period of time (like for example, gravity).

You can also apply a force every time bullet does a substep. Use the internal tick callback system or create your own btDynamicsWorld class where you re-implement the internal substep function. I do this when I model aircraft wings and the result is pretty much the same every time, and not framerate dependant.

Best regards,
Ola