leon wang Posted April 13, 2017 Share Posted April 13, 2017 i'm using babylon.js and oimo.js to build a simple scene which has boxes on top of another, there's 7 boxes, and after the scene was build the boxes starts moving and fall, i didn't apply any force and the gravity i'm sure is ok, anyone know what's the reason causing this? and how to stop the moving thanks very very much! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 13, 2017 Share Posted April 13, 2017 Hello can you reply it on the Playground? Is there a ground in your scene? Quote Link to comment Share on other sites More sharing options...
davrous Posted April 13, 2017 Share Posted April 13, 2017 Maybe it's too windy in the scene? I'm just kidding. Quote Link to comment Share on other sites More sharing options...
leon wang Posted April 14, 2017 Author Share Posted April 14, 2017 save button on playground not working fro me right now, can you guys please copy below codes and try? cubes will fall in 20 secs normally. thanks. BTW, love your show on MVA var createScene = function () { var scene = new BABYLON.Scene(engine); var gravityVector = new BABYLON.Vector3(0, -9.81, 0); var physicsPlugin = new BABYLON.OimoJSPlugin(); scene.enablePhysics(gravityVector, physicsPlugin); var ground = BABYLON.Mesh.CreateGround("ground", 200, 200, 100, scene); var mat1 = new BABYLON.StandardMaterial("mat1", scene); mat1.diffuseColor = BABYLON.Color3.Gray(); mat1.wireframe = true; ground.material = mat1; ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, restitution: 0.9 }, scene); //build cubes var mat_cube1 = new BABYLON.StandardMaterial("mat_cube1", scene); mat_cube1.diffuseColor = BABYLON.Color3.White(); var mat_cube2 = new BABYLON.StandardMaterial("mat_cube2", scene); mat_cube2.diffuseColor = BABYLON.Color3.Black(); var p = {x:0,y:0,z:-40}; [10,9,8,7,6,5,4,3,2,1].forEach(function (y) { [1,].forEach(function (x) { [1,].forEach(function (z) { var box = BABYLON.Mesh.CreateBox("cube_" + x + y + z, 1, scene); box.position = new BABYLON.Vector3(p.x + x , y - 0.5 , p.z + z ); //mat2.wireframe = true; ; //set physic box.physicsImpostor = new BABYLON.PhysicsImpostor(box, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0.1,friction:1, restitution: 0.1 }, scene); box.physicsImpostor.physicsBody.allowSleep = true; //box.physicsImpostor.physicsBody.isStatic = true; if ((x + y + z) % 2 == 0) { box.material = mat_cube1; } else { box.material = mat_cube2; } }) }); }); //create light var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 10, 0), scene); light.intensity = 1; //create camera var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(10, 15, -80), scene); camera.setTarget(new BABYLON.Vector3(-5,-10, 0)); camera.attachControl(canvas, false) return scene; }; Quote Link to comment Share on other sites More sharing options...
leon wang Posted April 14, 2017 Author Share Posted April 14, 2017 10 hours ago, davrous said: Maybe it's too windy in the scene? I'm just kidding. yeah, just like that. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 14, 2017 Share Posted April 14, 2017 Here is your PG: https://www.babylonjs-playground.com/#VA1KHM Ping @RaananW who may have an idea. One way could be to reduce gravity Quote Link to comment Share on other sites More sharing options...
jellix Posted April 15, 2017 Share Posted April 15, 2017 Is it the same with cannon.js? Indeed this is a problem of many physic engines. They handle the forces of overlaying boxes like if they fall onto each other although they already are in contact for a while. And due to floatingpoint operations there are always some numbers that had to be shortened, so you get some effects that you don't wanna have. The best would be that the engine recognizes the stable position of the boxes and would then reduce the calculation down to zero until the boxes move again. Don't know if there is an algorithm for that but ... obviously it should give one. Quote Link to comment Share on other sites More sharing options...
leon wang Posted April 17, 2017 Author Share Posted April 17, 2017 On 4/15/2017 at 8:53 PM, jellix said: Is it the same with cannon.js? Indeed this is a problem of many physic engines. They handle the forces of overlaying boxes like if they fall onto each other although they already are in contact for a while. And due to floatingpoint operations there are always some numbers that had to be shortened, so you get some effects that you don't wanna have. The best would be that the engine recognizes the stable position of the boxes and would then reduce the calculation down to zero until the boxes move again. Don't know if there is an algorithm for that but ... obviously it should give one. in cannon.js you can set allowsleep = true of cannonworld to avoid this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.