joshcamas Posted November 6, 2016 Share Posted November 6, 2016 Hia guys! I'm sure ya'll are familiar with the awesome intersection demo here on the PG:http://playground.babylonjs.com/#YMFIP Well, in my own game I'm having massive problems. Mainly, the mesh never collides with another mesh. I've tried showing bounding boxes to make sure their good, as well as switching between OBB and AABB, and nothing works. However, if I try checking intersection by itself (mesh.intersectsMesh(mesh)), then it works. I assumed it may have had to do with scaling or something, so I went and tried to replicate it on the PG. After trying to replicate it, I found an even stranger problem! It seems if you create an object after scene initiation, intersections won't work, or something?http://playground.babylonjs.com/#15VR2V#1 But this time, it always intersects with plane, no matter where I place the plane or the sphere! WHAT!? And I've made it so it waits a tick before it creates it, and have also tried waiting 10 ticks and such, just in case. Any ideas? Am I doing something wrong? Thanks! Quote Link to comment Share on other sites More sharing options...
Gijs Posted November 6, 2016 Share Posted November 6, 2016 In your second playground, both the if and else are red, but that wasn't the problem. I changed your playground so that it checks for collisions a frame after the objects have been added to the scene: http://playground.babylonjs.com/#15VR2V#3 And it works just fine. It adds the meshes after 120 frames, and it checks for collisions at frame 121. Black is no collision, red is collision. Maybe that helps Quote Link to comment Share on other sites More sharing options...
joshcamas Posted November 6, 2016 Author Share Posted November 6, 2016 Ok, I was afraid of this. Mannn idk how ima set this up! But yas you found the problem! And yeah I was going to make it turn white but then forgot to LOL Thanks a lot! Gijs 1 Quote Link to comment Share on other sites More sharing options...
joshcamas Posted November 6, 2016 Author Share Posted November 6, 2016 Actually, is there a way to not do this? Is there some sort of generation that can be forced out of tick? Cause that'd be rad EDIT: Just kidding! Simply run plane.computeWorldMatrix(true) and sphere.computeWorldMatrix(true) and boom! <3 getzel 1 Quote Link to comment Share on other sites More sharing options...
getzel Posted November 6, 2016 Share Posted November 6, 2016 Does intersectsMesh() works with lines ? And with complex loaded models or it makes a bounding box ? Does intersectsMesh() works with a box scaled, rotated etc ? (or i have to compute matrix) Does IntersectsPoint() works fine with a mesh moving fast, good performance ? I faced some issues. (Is it a good practice to detect collisions with raycast ?) Quote Link to comment Share on other sites More sharing options...
jerome Posted November 6, 2016 Share Posted November 6, 2016 intersectsMesh rely on bounding boxes and bounding spheres, so if your mesh has a BBOX (not sure for lines), it works whatever its origin (loaded or built-in). By default, the intersections are computed on axis aligned bounding boxes (AABB) even for scaled meshes, unless you specify you want the precise mode what enables OBB (oriented bounding boxes) computations, then taking in account rotations. In brief, you don't need to compute matrices. If you need a better accuracy than bounding boxes only, you have to use a physics engine what provides impostor more specific shapes. No idea about intersectsPoint(), didn't test it up now ... Generally, raycast computations are far more CPU intensive than BBOX computations. getzel 1 Quote Link to comment Share on other sites More sharing options...
getzel Posted November 6, 2016 Share Posted November 6, 2016 Thx for your answer. Finally the little issue I had with lines collision is simply because the engine takes the position centered of the line and not the points : var lineShoot = BABYLON.Mesh.CreateLines("lines", [ new BABYLON.Vector3(2, 8.8, -2), new BABYLON.Vector3(2, 8.8, -4) ], scene, false); For example, here x:2 won't be recognized. It's better to put the points at x:0 and lineShoot.position.x = 2. 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.