【发布时间】:2023-01-30 23:44:20
【问题描述】:
我正在尝试将 BabylonJS 中的物理 (AmmoJS) 用于导入的网格。 对于我即时创建的网格,一切正常,但是当我导入网格时,它会从地面掉落。
const ground = BABYLON.MeshBuilder.CreateBox("ground",
{ width: 10, height: 1, depth: 10}, scene);
ground.receiveShadows = true;
ground.checkCollisions = true;
ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground , BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, friction: 0.5, restitution: 0.5 }, scene);
BABYLON.SceneLoader.ImportMesh(["car9"], "models/", "Policecar.glb", scene, function (meshes, particleSystems, skeletons) {
for (let i in meshes) {
meshes[i].checkCollisions = true;
}
let policecar = meshes[0];
policecar.physicsImpostor = new BABYLON.PhysicsImpostor(policecar, BABYLON.PhysicsImpostor.MeshImpostor, { mass: 10, friction: 0.5, restitution: 0.5 });
policecar.position = new BABYLON.Vector3(0, 10, 0);
policecar.scaling = new BABYLON.Vector3(scale, scale, scale);
});
当我把警车的restition改成0或1时,它没有掉在地上,但奇怪地反弹了几次,然后倒在了它的一边。使用 BoxImpostor 而不是 MeshImpostor 它会直接掉落。
有任何想法吗?
【问题讨论】:
标签: mesh babylonjs physics-engine ammo.js