Uniform Posted July 11, 2016 Share Posted July 11, 2016 Hi guys, I have biiig issues with .intersectsMesh() function And to begin with I'd like to ask you why the heck is the ball becoming red even after the commented out bounding boxes? http://www.babylonjs-playground.com/#QGKMK Quote Link to comment Share on other sites More sharing options...
vsh91 Posted July 11, 2016 Share Posted July 11, 2016 This is just a guess, but perhaps the bounding box on the third sphere or plane is off/oversized. Maybe print out the dimensions to possibly rule that out. Update** It seems like that's not the issue. I enabled showBoundingBox on all the objects. http://www.babylonjs-playground.com/#QGKMK#5 Quote Link to comment Share on other sites More sharing options...
gryff Posted July 12, 2016 Share Posted July 12, 2016 Quote And to begin with I'd like to ask you why the heck is the ball becoming red even after the commented out bounding boxes? @Uniform : You are not commenting out the actual bounding boxes of the two planes. That code is actually just showing you what/where the bounding boxes are that are being used by the two conditions (balloon1.intersectsMesh(plan1, false)) and (balloon2.intersectsMesh(plan1, true)) cheers, gryff Quote Link to comment Share on other sites More sharing options...
Uniform Posted July 13, 2016 Author Share Posted July 13, 2016 On 12/07/2016 at 2:27 AM, gryff said: @Uniform : You are not commenting out the actual bounding boxes of the two planes. That code is actually just showing you what/where the bounding boxes are that are being used by the two conditions (balloon1.intersectsMesh(plan1, false)) and (balloon2.intersectsMesh(plan1, true)) cheers, gryff Thank you a lot @gryff It is really strange because i feel like the bounding box has been designed for me and I have no word to say, quite strange. But anyway it still doesn't resolve my issue. Here is the code: http://www.babylonjs-playground.com/#1GHPEG (open the console and press run) Basically, I am trying to map the terrain into a 2 dimension matrix of 0 for non walkable and 1 for walkable. (for further pathfinding use) I am planning to use an abstract mesh as a pointer but for visual purposes i am using a mesh. Every frame this mesh will move by incrementations of 0.5 units on the x axis. When it reaches the border of the ground the pointer will increment the z axis until it reaches the top right corner of the terrain. I use the intersectMesh() function to detect wether the pointer mesh encounters another mesh, in this case the big red box. I am printing the matrix into the console and i am limiting the computing to the 3 first frames because everything is similar after it. This is the algorithm: var pathMatrix = []; // initializing an array function computeMatrix(){ var begin = [-7.5,-7.5]; // bottom left corner of the ground var end = [7.5,7.5]; // top right corner of the ground var incr = 0.5; // Incremental value, crashes if set to 0.1... strange! pointer.position = new BABYLON.Vector3(begin[0],0.3, begin[1]); var tempArray = []; // temp array representing each row of the Matrix var stop = false; while(stop == false){ if(pointer.intersectsMesh(box,true)){ tempArray.push(0); } else{ tempArray.push(1); } // Condition of stop if (pointer.position.x == end[0] && pointer.position.z == end[1]){ pathMatrix.push(tempArray); tempArray = []; stop = true; } else if (pointer.position.x == 7.5){ pathMatrix.push(tempArray); tempArray = []; pointer.position.x = -7.5; pointer.position.z += incr; // go to next row } pointer.position.x += incr; // go to next column } // Print each row of the array in console for(var i = 0; i<30;i++){ console.log(pathMatrix[i]); } pathMatrix = []; // reset the matrix arrau } I would be very grateful if anyone can help me to resolve this issue. Basically I am trying to obtain a 2dimension matrix based on the abstract representation of the ground mesh. This matrix represents a collision mask that I will be able to use with my pathfinding library. If you have other suggestions of how I can do this because this might be a bit overkill (especially moving an object several times per frame) Thanks, Uniform Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 13, 2016 Share Posted July 13, 2016 I'm sorry but I did not get the problem here can you try to explain me with a simple playground where the problem is? Quote Link to comment Share on other sites More sharing options...
Uniform Posted July 13, 2016 Author Share Posted July 13, 2016 1 hour ago, Deltakosh said: I'm sorry but I did not get the problem here can you try to explain me with a simple playground where the problem is? Wow didn't expect an answer from the mighty creator Well if you look at the matrix output the first frame I obtain only zero's. It is okay because the first frame everything is created. But then the next frames I get matrices only 1's. So because there is this big red box in the middle of the ground the matrix should have some 0 in the place of 1's because that means that the pointer encountered some collision and thus there is a mesh in the way. Which is not the case here because I only get an array of 1. Quote Link to comment Share on other sites More sharing options...
Uniform Posted July 13, 2016 Author Share Posted July 13, 2016 I made a quick video to illustrate my problem. Quote Link to comment Share on other sites More sharing options...
Uniform Posted July 13, 2016 Author Share Posted July 13, 2016 So basically the pointer is doing this but 60 times per second. http://www.babylonjs-playground.com/#16JB3C#2 # Check the console (just validates my algorithm so something is wrong with the function or it is not designed to be used that way==> too fast) Any help is welcome Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 13, 2016 Share Posted July 13, 2016 ok gotcha:) Not a big deal then. This is because the internal bounding info are only updated when a frame is rendered for performance reason. Just add this code: pointer.computeWorldMatrix(true); // true to force all inner values to get updated RIGHT NOW :) if(pointer.intersectsMesh(box,true)){ tempArray.push(0); } else{ tempArray.push(1); } Uniform 1 Quote Link to comment Share on other sites More sharing options...
Uniform Posted July 13, 2016 Author Share Posted July 13, 2016 Oh god thank you. I have tried this function before but I placed it in the beginning of the function instead of the while loop. Thank you so much @Deltakosh ! GameMonetize 1 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.