所以,我在使用 babylon.js 时遇到了麻烦。我试图做一个简单的例子,我在我的玩家对象和地面上有盒子碰撞器,并应用了重力和碰撞的物理。对于我可能做错的事情,我已经没有想法了。请帮忙!我将提供游乐场链接,因为人们不认为我们使用它,以及原始代码。
链接:http ://www.babylonjs-playground.com/#1PK6ED#1
原始代码:
window.addEventListener('DOMContentLoaded', function(){
var canvas = document.getElementById('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var engine = new BABYLON.Engine(canvas, true);
var createScene = function(){
//var gravity = parseFloat(0.1);
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera("ArcRotateCamera", 1, 0.8, 10, new BABYLON.Vector3(0, 0, 0), scene);
camera.attachControl(canvas, false);
var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene);
scene.enablePhysics(new BABYLON.Vector3(0, -10, 0), new BABYLON.OimoJSPlugin());
scene.collisionsEnabled = true;
var player = BABYLON.Mesh.CreateBox("player",2,scene);
player.position = new BABYLON.Vector3(0,20,0);
player.checkCollisions = true;
var wing = BABYLON.Mesh.CreateBox("wing",2,scene);
wing.position = new BABYLON.Vector3(0,0,0);
wing.scaling.x = 2;
wing.scaling.y = .3;
wing.checkCollisions = true;
wing.parent = player;
camera.parent = player;
var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "data/images/heightMap_jpg.jpg", 400, 400, 500, 0, 10, scene, false);
var meshesColliderList = [];
for (var i = 1; i < scene.meshes.length; i++) {
if (scene.meshes[i].checkCollisions && scene.meshes[i].isVisible) {
scene.meshes[i].setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, { mass: 0, friction: 0.5, restitution: 0.7 });
meshesColliderList.push(scene.meshes[i]);
}
}
console.log(meshesColliderList);
return scene;
}
var scene = createScene();
engine.runRenderLoop(function(){
scene.render();
});
window.addEventListener('resize', function(){
engine.resize();
});
});