Physics Scale Factor (Havok)


We’ve been using Havok via the @babylonjs/havok package for some projects that involve rendering both very large and very small scenes. One thing that would make our lives a lot easier is if there was an API to set a “simulation scale factor” directly in Havok.

Basically, we want to be able to specify a scale factor (like 100) and have Havok automatically treat all the units as centimeters instead of meters. This would be super helpful for working with huge or tiny scenes. Under the hood, stuff like positions, velocities, forces, and the max speed cap would need to get multiplied by the scale factor.

We hacked together our own scale factor wrapper around havok to do this, but It would be way cleaner and probably more performant if this was just built into Havok natively.


If you’re a user who’s attempting to implement this in your project, you’ll find this thread useful:

1 Like

cc @eoin / @Cedric

1 Like

IIRC there are some clamped values (for speed?) in Havok. So, I don’t think this is something that can be done without its load of troubles. Idk how it will behave with float precision issues as well. Do you provide such scaling mecanism in Havok @eoin ?


An API for tweaking speed clamps already exists:

The key benefit of a simulation scale factor is reducing floating point errors, which can really start to add up in tiny scenes. Let’s say you’ve got a 1cm x 1cm scene. Right now, that 1cm length is getting stored as 0.01 in Havok’s guts.

So while 1cm is exactly 0.01m in the real world, inside the simulation that 0.01 might end up as something like 0.0099999999 due to rounding errors. Those tiny discrepancies can snowball into visible glitches.

But if you could tell Havok, “hey, multiply everything by 100 internally and treat it as centimeters”, then that 1cm length would be represented as a nice clean “1.0” under the hood. Much less opportunity for precision loss to creep in and far more numerically stable.

We actually used to have a world “unit scale” factor in our SDK, but it was removed (8 years ago :open_mouth:) - the feeling at the time was that it was quite high maintenance and difficult to ensure that it worked correctly. None of our customers were using that functionality anyway; I remember we even had customers whose engine units were inches, and they always just converted to Havok units at the boundary.