Forces in Havoc off by a factor of 2

Hi folks,

While converting my games from Ammo to Havoc, I noticed that applyForce was behaving very differently. I recognize that there are many difference between the engines, especially at low velocities, but it appears that either applyForce (or gravity) has an error factor of 2 somewhere.

I derived this playground from the Havoc applyForce demo to make it easier to show the difference. Click and hold the primary/left mouse button to oppose gravity perfectly. Use any other mouse button to oppose with half that force. Use the havoc variable on line 33 to switch between Ammo and Havoc as the physics engine. You’ll see that Ammo works as expected (the left button equalizes gravity) but with Havoc, it’s the right button. In my experimentation, this holds true across variations in mass and gravity.

Looking at the code, I didn’t spot any issues in the plugin code. I don’t see a way to look inside Havoc’s code, but I think that’s by design, right?

Cheers, Brian

1 Like

Also, obligitory.

What are you testing for?

1 Like

Adding @Cedric @carolhmj and @eoin

Hmmm, I can confirm the different behavior, I think it’s even easier to see it without the mouse impulses, on ammo: A very simple example of Havok applyForce | Babylon.js Playground (babylonjs.com), the sphere stays in place, while in havok: A very simple example of Havok applyForce | Babylon.js Playground (babylonjs.com), it slowly goes up. :thinking:

Eoin will be the best person to answer what is going on :slight_smile:

1 Like

@carolhmj Inside HavokPlugin.applyForce(), the force is scaled by the _fixedTimeStep - if the delta time used by the next HavokPlugin.executeStep() is different, that can result in a discrepancy between the observed and the expected effect of that force. So, applyForce() really should use the value that will be passed into executeStep(). Would you be able to sort that out?

Sorry, I ended up not following on that, let me assign myself to it :sweat_smile:

1 Like