dav74 Posted December 8, 2013 Share Posted December 8, 2013 Hi,when my scene begins i've "intersectsMesh" at true (even if there is no collision in my scene). After the first frame, all is ok : "intersectsMesh" is at false.var canvas = document.getElementById("renderCanvas");var time=0;var vitesseSph=0.2;var engine = new BABYLON.Engine(canvas, true); var scene = new BABYLON.Scene(engine);var camera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(0,2, 0), scene);camera.attachControl(canvas);var light = new BABYLON.PointLight("pointLumineux1", new BABYLON.Vector3(100, 100, 0), scene); var plan=BABYLON.Mesh.CreatePlane("sol",200,scene);plan.rotation.x=Math.PI/2;var sphere=BABYLON.Mesh.CreateSphere("sph",20,5,scene)sphere.position=new BABYLON.Vector3(0, 30, 70);var mat1= new BABYLON.StandardMaterial("maSph1",scene);mat1.diffuseColor = new BABYLON.Color3(1,0,0);var mat2= new BABYLON.StandardMaterial("maSph2",scene);mat2.diffuseColor = new BABYLON.Color3(0,0,1);sphere.material=mat1;scene.gravity = new BABYLON.Vector3(0, -1, 0);camera.ellipsoid = new BABYLON.Vector3(1, 1, 1);camera.applyGravity = true;scene.collisionsEnabled = true;camera.checkCollisions = true;plan.checkCollisions = true;sphere.checkCollisions = true;scene.registerBeforeRender(function(){ time=time+(1/BABYLON.Tools.GetFps()); if (sphere. intersectsMesh(plan,true)==false){ sphere.position.y=30-0.5*2*Math.pow(time,2); } else { sphere.material=mat2; }}); engine.runRenderLoop(function () { scene.render(); }); in the beginning, my sphere is blue (instead red) All is ok if i add a "if (time>0)" :scene.registerBeforeRender(function(){ if (time>0){ if (sphere. intersectsMesh(plan,true)==false){ sphere.position.y=30-0.5*2*Math.pow(time,2); } else { sphere.material=mat2; } } time=time+(1/BABYLON.Tools.GetFps());}); Thank you for your help Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 8, 2013 Share Posted December 8, 2013 This is because the first render compute all world matrices for your meshes. If you want, you can call sphere.computeWorldMatrix(true) and plane.computeWorldMatrix(true) to ensure that even before the first frame, your intersectsMesh will work Quote Link to comment Share on other sites More sharing options...
dav74 Posted December 8, 2013 Author Share Posted December 8, 2013 Thank you, all is ok : no more need (if (time>0)....) 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.