Havok set position of physics body

When using cannon I was able to force a physics body to get a new position by setting the new position in cannon directly:

constr newPosition = new Cannon.Vec3(x, y, z)
myMesh.physicsImpostor.physicsBody.position = newPosition

Is something like this possible with the new havok engine? It’s ab it difficult to figure this stuff out, since there seems to be not documentation available of the underlying engine?

This seems to work:

const plugin = scene.getPhysicsEngine().getPhysicsPlugin()
plugin_hknp.HP_Body_SetPosition(mesh.physicsBody._pluginData.hpBodyId, [x, y, z])

@Cedric Is there any documentation of the underlying havok physics engine publicly available?

1 Like

You can set body.disablePreStep to false, change the position of the transformNode linked to the body, then set body.disablePreStep to true after the next frame has executed

3 Likes

@Raggar Feels like the same thing with extra steps :grimacing: Appreciate the help though, it’s probably a viable alternative. For my case however, I need to execute this in a registerBeforePhysicsStep callback, so setting it directly probably makes a bit more sense. First I need to figure out how to actually implement/use a registerBeforePhysicsStep callback though, since apparently it’s not present in the v2 system

It is the same thing indeed, this update step is disabled by default because it improves performance greatly :slight_smile: Performance Tips | Babylon.js Documentation (babylonjs.com)

As for the registerBeforePhysics…, you could try scene.onBeforePhysicsObservable instead?

2 Likes

@carolhmj Yes that’s exactely what I was end up using :slight_smile: Thanks! Do you maybe have any info regarding documentation of the havok engine itself?

What @carolhmj said. For performance reason (because 99.99% of time, it’s not needed), the prestep that sets the physics body transform from the mesh transform is disabled. Change the boolean value to be able to tweak it. Doing it with a direct Havok call will make your code not compatible with newer Havok .wasm (potentialy) or another Physics Engine.

Hi @Cedric. How can we do this when our transform node is child of another mesh or transform node which has a position?

More or less same issue as Havoc: problems with parented meshes - #5 by Cedric
I’m investigating that today.

2 Likes