Jump to content

problem with intersectsMesh


Recommended Posts


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

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...