Havok - wake up from sleep mode

Hello everybody,

I continue my merry way in Havok and its motorized constraints. I just noticed that an unused motor whose bodies are not moving enters into sleep mode quickly (about 250ms).

I made a small example that shows this. Depending on when the timer is triggered, the motor is running or not. Change the timer to 2000 at line 80 to reproduce the issue.

I couldn’t find an API function to explicitly wake the bodies attached to the constraint. The only reference to sleep mode appears in the constructor of PhysicsBody, at the time of its initialization, but this is not sufficient in my case.
Moreover, in the V1 physics engine, there was the PhysicsPlugin.wakeUpBody() function to do this.

Does anyone know how to wake up a body?

Thanks in advance!

Hello!

We can’t manually wake up a body as that’s supposed to be controlled by the physics engine only, but it’s weird the motor is not moving :thinking: @eoin do you have an idea of what’s going on?

@eoin Any news about this? I’m very stuck with this issue.

You can wake up the body by applying a force or impulse(can be zero as well, as the function itself wakes up the body it seems)

3 Likes

Thank you very much, I confirm that this workaround wakes up the bodies.

function wakeUpBody(body) {
  body.applyForce(new Vector3(0, 0, 0), body.transformNode.position)
}

I can go on with this for now, but a cleaner way to wake up a body would be welcome.

Oh sorry! I totally missed this last week; was pulled into some projects which took a bunch of my time. The upcoming version of the WASM will have additional functions for sleep control, but looks like you’ve found a bug; changing some of the constraint params don’t send an activation request to the attached bodies. I’ll be sure to get this fixed up too, but Raggar’s workaround should hold you over 'til then. Thanks Raggar!

3 Likes

Thank you, I will monitor the introduction of this feature :slight_smile:

Hi @eoin ! I was wondering if you were still planning on adding these additional sleep control functions to the WASM? That would be awesome, and thank you :slight_smile:

I see it in the Havok engine as HP_Body_SetActivationState() where you can set a bodyId as ACTIVE or INACTIVE.

I don’t see anything in the Havok Plugin, yet.

Maybe something like this would work?

havokPlugin._hknp.HP_Body_SetActivationState( physicsBody._pluginData.hpBodyId, havokPlugin._hknp.ActivationState.ACTIVE)

May be prudent to test to see if it has your desired result?

1 Like

That’s right; we have exposed a bunch of functions in the WASM for sleep control (we call it activation/deactivation, rather than sleeping):

    /** Try to set the activation state of a body. */
    HP_Body_SetActivationState(bodyId: HP_BodyId, activationState: ActivationState): Result;
    /** Get the current activation state of a body. */
    HP_Body_GetActivationState(bodyId: HP_BodyId): [Result, ActivationState];
    /** Set the activation behavior of a body. See `ActivationControl` for more details. */
    HP_Body_SetActivationControl(bodyId: HP_BodyId, activationControl: ActivationControl): Result;
    /** Set the activation priority of a body. `priority` should be in the range [-127, 127]. Defaults to 0.
     * A body with simulation controlled activation will only be activated by interactions from other bodies
     * whose priority is >= `priority` */
    HP_Body_SetActivationPriority(bodyId: HP_BodyId, priority: number): Result;

These just need to be exposed in the HavokPlugin. The last two methods do offer more control than other physics engines do, though, so need to be careful we’re not adding an interface which doesn’t make sense for those potential other engines.

(Also, the havok package v1.3.0 fixed the reporter’s bug where changing the constraint parameters didn’t activate attached bodies)

1 Like

Thank you so much for your help, @HiGreg and @eoin :smile:

I was also wondering if Havok has a function to set the sleep kinetic energy threshold of bodies? (Similar to PhysX’s setSleepThreshold() and Bullet’s setSleepingThresholds())