DiV Posted January 8, 2018 Share Posted January 8, 2018 Hello, I'm sorry for the stupid question, but how do I detect an intersection? I followed the playground example, but it doesn't work for me. Here is the code: var portal = BABYLON.Mesh.CreateBox("portal", 20, scene); portal.position = new BABYLON.Vector3(0, -5, -30); portal.rotation = new BABYLON.Vector3(0, 3.14, 0); portal.showBoundingBox = true if (ellipsoid.intersectsMesh(portal, false)) { //ellipsoid attached to the camera alert("!!!"); //Message never appears } Quote Link to comment Share on other sites More sharing options...
Wingnut Posted January 8, 2018 Share Posted January 8, 2018 Hi DiV, welcome to the forum. It's not a stupid question at all. Your code looks right. https://www.babylonjs-playground.com/#11WNDR#20 There's a playground that might help. What IS 'ellipsoid'? It is a flat mesh? Could it be backwards/upside-down? (I'm not sure WHY that would matter, though.) I don't know why it would matter, but maybe reverse the intersection tester line... like this... if (portal.intersectsMesh(ellipsoid, false)) Anyway, those are just some quick checks. If you can use our playground... to reproduce the problem, then make a save... and send us the URL herre in this thread, we can all see the issue. It COULD be... related to the thickness of ellipsoid... if ellipsoid is flat. Or reversed. More info, please. Reproduce a test scene in playground, if possible, thx. There are some sneaky ways to "thicken" the bounding box of a flat mesh/plane... without making the mesh BE thicker. Our friend Adam once made a bounding box from a blank mesh. In that playground, line 26 FORCES a boundingbox size... so I think we can figure out how to "thicken" something, as needed. Talk soon, report discoveries, please. (thx) DiV 1 Quote Link to comment Share on other sites More sharing options...
DiV Posted January 8, 2018 Author Share Posted January 8, 2018 I think I found the solution. It attaches a box to my camera. May not be the best way to code it but it works, which is enough for me. Thank you! var portal = BABYLON.Mesh.CreatePlane("portal", 20, scene); portal.position = new BABYLON.Vector3(0, -5, -30); portal.rotation = new BABYLON.Vector3(0, 3.14, 0); let collider = BABYLON.MeshBuilder.CreateBox("collider", {size: 3}, scene); collider.parent = camera; collider.actionManager = new BABYLON.ActionManager(scene); let action = new BABYLON.ExecuteCodeAction( { trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: { mesh: portal } }, (evt) => { window.open("https://vk.com","_self"); } ); collider.actionManager.registerAction(action); RaananW, GameMonetize and Wingnut 3 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.