I try to translate the next Godot tutorial example to Babylon.js: Importing 3D Objects The author uses kenney_platformerkit2 But there is a problem:
However, there’s one small problem: it seems Kenney exported this model with an offset:
It would much better if the crate were centered relative to the parent node, so that when the
RigidBody
rotates about its center, so will the mesh. To fix this, select theMeshInstance
node and set its Translation property to(-0.5, -0.25, 0.5)
.
I want to make the same with Babylon.js. I found in the documentation: Pivots
I can set a pivot point like this:
crate.setPivotPoint(new BABYLON.Vector3(-0.5, -0.5, -0.5));
or like this:
crate.setPivotMatrix(BABYLON.Matrix.Translation(-0.5, -0.5, -0.5))
But both set only X and ignore Y and Z
The gray box is in the center.
This is my sandbox example: Crate and Pivot Point
const box = BABYLON.MeshBuilder.CreateBox("box", { width: 0.5, height: 0.5, depth: 0.5 }, scene);
async function load()
{
const result = await BABYLON.SceneLoader.ImportMeshAsync(null, "models/", "crate.glb", scene);
const crate = result.meshes[0];
crate.setPivotPoint(new BABYLON.Vector3(-0.5, -0.5, -0.5));
// crate.setPivotMatrix(BABYLON.Matrix.Translation(-0.5, -0.5, -0.5))
console.log(crate.getAbsolutePivotPoint());
}
load();