Javascript 碰撞检测、重叠网格
在以下示例中: 当长方体向上移动时,为什么球体网格与长方体网格重叠(或略微落入其中)?当长方体向上移动球体时,是否有方法使球体不与长方体重叠 以下是示例中的相关代码,以供参考:Javascript 碰撞检测、重叠网格,javascript,collision-detection,babylonjs,Javascript,Collision Detection,Babylonjs,在以下示例中: 当长方体向上移动时,为什么球体网格与长方体网格重叠(或略微落入其中)?当长方体向上移动球体时,是否有方法使球体不与长方体重叠 以下是示例中的相关代码,以供参考: var createScene = function () { // This creates a basic Babylon Scene object (non-mesh) var scene = new BABYLON.Scene(engine); // This creates and
var createScene = function () {
// This creates a basic Babylon Scene object (non-mesh)
var scene = new BABYLON.Scene(engine);
// This creates and positions a free camera (non-mesh)
var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 10, -20), scene);
// This targets the camera to scene origin
camera.setTarget(BABYLON.Vector3.Zero());
// This attaches the camera to the canvas
camera.attachControl(canvas, true);
// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;
// Our built-in 'sphere' shape. Params: name, subdivs, size, scene
var sphere = BABYLON.Mesh.CreateSphere("sphere1", 8, 2, scene);
// Move the sphere upward 1/2 its height
sphere.position.y = 2;
var ground = BABYLON.Mesh.CreateBox("box1",2.0, scene);
ground.position.y = -1;
sphere.material = new BABYLON.StandardMaterial("s-mat", scene);
scene.enablePhysics(new BABYLON.Vector3(0, 0, 0));
sphere.physicsImpostor = new BABYLON.PhysicsImpostor(sphere, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 1, restitution: 0 }, scene);
ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, restitution: 0 }, scene);
scene.registerBeforeRender(function () {
if(ground.position.y <= 2.5){
ground.position.y += .05;
}
sphere.physicsImpostor.setLinearVelocity(new BABYLON.Vector3(0,0,0));
sphere.physicsImpostor.setAngularVelocity(new BABYLON.Quaternion(0,0,0,0));
});
return scene;
};
var createScene=function(){
//这将创建一个基本的巴比伦场景对象(非网格)
var场景=新巴比伦。场景(引擎);
//这将创建并定位自由摄影机(非网格)
var摄像机=新巴比伦。自由摄像机(“摄像机1”,新巴比伦。矢量3(0,10,-20),场景);
//这将使摄影机以场景原点为目标
camera.setTarget(bylon.Vector3.Zero());
//这会将相机附加到画布上
照相机.附件控件(画布,真实);
//这将创建灯光,将0,1,0-瞄准天空(非网格)
var light=新巴比伦。半球光(“light1”,新巴比伦。矢量3(0,1,0),场景);
//默认强度为1。让我们将灯光调暗一点
光照强度=0.7;
//我们内置的“球体”形状。参数:名称、细分曲面、大小、场景
var sphere=BABYLON.Mesh.CreateSphere(“sphere1”,8,2,场景);
//将球体向上移动其高度的1/2
球体位置y=2;
var ground=bylon.Mesh.CreateBox(“box1”,2.0,场景);
地面位置y=-1;
sphere.material=新巴比伦标准材质(“s-mat”,场景);
场景.使能物理学(新巴比伦.矢量3(0,0,0));
sphere.physicsImpostor=新巴比伦.physicsImpostor(sphere,巴比伦.physicsImpostor.SphereImpostor,{mass:1,restoration:0},场景);
ground.physicsImpostor=新巴比伦.physicsImpostor(地面,巴比伦.physicsImpostor.BoxImpostor,{mass:0,restoration:0},场景);
scene.registerBeforRender(函数(){
如果(地面位置y