How to enable faster moving rigidbodies in HAVOK?

No matter the force etc, I can never get rigidbodies to move faster than a certain speed.

I know and understand that velocity is capped, and it’s because we don’t want things to fly through each other.

However, it’s set so low, that everything appears like under water in my projects, I need fast (really fast) moving rigid bodies, andNOT by setting their absolute position, I need it to be handled in the physics engine (lift the max velocity setting) - How would one do that?

cc @Cedric and @carolhmj

Seems like the max linear velocity magnitude is set at a default of 200 units

Is there some limit with velocity @eoin ?
@Frits_Lyneborg A simple work around is to change units. And convert everything to that unit. Like 1unit = 1 cm to 1unit = 1meter. That way, you can have everything going 100x faster.

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

Thanks - actually I want to slow everything down… cap it, but I found out how to apply opposite forces.

I don’t know if something changed in subsequent versions of the havok wasm but I couldn’t change the maximum velocity of rigibodies using this function: https://playground.babylonjs.com/#Z8HTUN#667

Could you provide an update on how to perform the same operation in havok 1.1.3?

Yeah, we did change this, sorry. Hope we won’t be changing this again, and we will have to work out what we want to do here long-term, but in the meantime, here’s an updated function:

    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], 300);

        tsbuf[32] = maxLinVel;
        tsbuf[33] = maxAngVel;
        tsbuf[60] = maxLinVel;
        tsbuf[61] = maxAngVel;
        tsbuf[88] = maxLinVel;
        tsbuf[89] = maxAngVel;
        tsbuf[144] = maxLinVel;
        tsbuf[145] = maxAngVel;
        tsbuf[172] = maxLinVel;
        tsbuf[173] = maxAngVel;
        tsbuf[200] = maxLinVel;
        tsbuf[201] = maxAngVel;
        tsbuf[228] = maxLinVel;
        tsbuf[229] = maxAngVel;
    }
4 Likes

Thanks a lot! It works just fine :slight_smile:

Reference playground for anyone interested: https://playground.babylonjs.com/#Z8HTUN#673

1 Like

Hi @eoin ,

It appears that this no longer works in v1.3.0 :sweat_smile:.

Have you reached a decision on a long term approach for this?

Hmmm, not sure what caused this to change, but world1[9] just needs to be world1[8].
In the next version, I’ll add a function to do this change, so we don’t need these magic numbers.

3 Likes