I want to set my tera model as a map landscape, but tree goes through it.
I use babylonjs and ammojs-typed.
I need help, don’t know what to do.
What I need is for the tera model to be a physical body that other meshes will not pass through. I also want the geometry of my models to be used.
private async game(): Promise<BABYLON.Scene> {
this.scene.useRightHandedSystem = true;
const ammo = await Ammo.call(this);
this.scene.enablePhysics(
new BABYLON.Vector3(0, -9.81, 0),
new BABYLON.AmmoJSPlugin(true, ammo)
);
const camera = new BABYLON.ArcRotateCamera(
'camera',
Math.PI / 2,
Math.PI / 2,
10,
new BABYLON.Vector3(0, 0, 0),
this.scene
);
camera.attachControl(this.canvas, true);
const light = new BABYLON.DirectionalLight(
'light',
new BABYLON.Vector3(1, -1, 0),
this.scene
);
light.intensity = 0.7;
const shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
BABYLON.SceneLoader.ImportMesh(
'',
'src/static/models/',
'tera.glb',
this.scene,
function (meshes, particleSystems, skeletons) {
for (const i in meshes) {
meshes[i].checkCollisions = true;
console.log('check', meshes[i].checkCollisions, i);
}
const policecar = meshes[0];
policecar.scaling.scaleInPlace(0.1);
policecar.physicsImpostor = new BABYLON.PhysicsImpostor(
policecar,
BABYLON.PhysicsImpostor.MeshImpostor,
{ mass: 0, friction: 0.1, restitution: 0.9, shape: policecar }
);
}
);
BABYLON.SceneLoader.ImportMesh(
'',
'src/static/models/',
'tree_dry.glb',
this.scene,
function (meshes, particleSystems, skeletons) {
for (const i in meshes) {
meshes[i].checkCollisions = true;
console.log('check', meshes[i].checkCollisions, i);
}
const policecar = meshes[0];
policecar.scaling.scaleInPlace(0.1);
policecar.physicsImpostor = new BABYLON.PhysicsImpostor(
policecar,
BABYLON.PhysicsImpostor.MeshImpostor,
{ mass: 10, friction: 0.1, restitution: 0.9, shape: policecar }
);
}
);
this.engine.runRenderLoop(() => {
this.scene.render();
});
window.addEventListener('resize', () => {
this.engine.resize();
});
return this.scene;
}
}
I tried different meshimposters, but nothing works
New contributor
fra1m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.