How to enable faster moving rigidbodies in HAVOK?

Raggar is precisely correct. The default cap on linear velocity is 200 m/s (which is about two thirds the speed of sound, so pretty fast :)). This default limit this not due to objects going through each other, as we always use continuous collision detection, but rather it’s likely a mistake to have bodies moving at that speed.

As Cedric suggested, if your object feel like they’re moving slowly, you might want to check the scale of your scene and ensure that the objects are correctly sized. While a configurable limit isn’t exposed in the exported WASM functions, it is possible to change by reaching into the plugin memory. However, I’d strongly suggest verifying that the scale of your scene is correct. You’ll also want to be conscious of the fact that extremely fast moving objects will require more memory and cpu time, due to the additional work that continuous collision detection will do. If you’re trying to simulate bullets or something similar, it’s much better to use raycasts.

// Hack to change the limits on max velocity. Pass in the BABYLON.HavokPlugin(), before creating any bodies
function setMaxLinVel(havokPlugin, maxLinVel, maxAngVel) {
    const heap = havokPlugin._hknp.HEAP8.buffer;
    const world1 = new Int32Array(heap, Number(havokPlugin.world), 100);
    const world2 = new Int32Array(heap, world1[9], 500);
    const mplib = new Int32Array(heap, world2[428], 100);
    const tsbuf = new Float32Array(heap, mplib[8], 100);

    tsbuf[32] = maxLinVel;
    tsbuf[33] = maxAngVel;
    tsbuf[60] = maxLinVel;
    tsbuf[61] = maxAngVel;
    tsbuf[88] = maxLinVel;
    tsbuf[89] = maxAngVel;
}
7 Likes