max123 Posted November 19, 2016 Share Posted November 19, 2016 I have a character, a target (a box attached to a camera) and wall. For some reason, when Target is behind Wall, Character can still see the bloody Target! What's the correct way of using pickWithRay? Is there a way to visualize rays, e.g. draw a line? Quote Link to comment Share on other sites More sharing options...
getzel Posted November 19, 2016 Share Posted November 19, 2016 It is better if you send a Playground of your bloody shooting demo There is a predicate function with this method. And you have in parameter the mesh hitten. function predicate (mesh){ return mesh === target; } It will return true if the wall is not between in theory. http://www.html5gamedevs.com/topic/2114-exclude-some-meshes-when-scenepicking/ Check that your ray is well positioned (y > 0), make a big wall to test. I had some issues when I tried to pick a character's mesh. When he turned, the result was false because he's skinny. So I attached an invisible box to him and it was ok. Sometimes the ray touched the character even behind wall but maybe it's over now. A debug function to draw the ray could be cool. ------- I have a little question : is there a function to pick multiple objects with a ray and return an array of pickedMesh ? (like a bullet passing through several things) Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 20, 2016 Share Posted November 20, 2016 Heya getzel, max, and any other bloody readers. G... I don't think there IS a multi-hit ray... but... are you thinking what I am thinking? You mentioned predicate. What if... you kept targeting the same mesh, but you repeatedly change the ray's origin/source mesh... to be the most recently-hit mesh? Keep moving the ray launch-point... to the hit mesh... and fire again. I think rays ALWAYS stop at the first hit. But then... store that hit in a "whichMeshHitSoFar" array, then change the ray origin to the hit mesh, and fire again. Rinse and repeat... until the origin and the target are the same mesh. No need to fire any more rays, then. Can you imagine this? 5 mesh in a line, try to fire ray from 1 to 5. Ray hits mesh 2 (a blocker). Push mesh2 into array, move ray origin to mesh2, and fire again. Hits mesh3 (a blocker). Store, make it origin, and fire again.... etc etc. Lily pad hopping! Might work. Sort of demented, so likely fun! Carpenter 1 needs the distance to carpenter 5. But while he is extending his tape measure towards C5, it hits carpenter 2 and is blocked. So C1 asks C2 to pull the measuring tape (and spool) to himself, and continue measuring "down the line". C2 gathers the tape and spool, and then extends the tape measure towards C5, but it hits carpenter 3... etc, etc, etc. heh. Goofy. Hand-along tape measuring. Quote Link to comment Share on other sites More sharing options...
getzel Posted November 20, 2016 Share Posted November 20, 2016 Thx Wingnut. I already thought about that. A function pickAllWithRay in Babylon would be cool. There is already one doing this in Three.js. I dont know if its with your algorithm or something else more obscure. Quote Link to comment Share on other sites More sharing options...
max123 Posted November 20, 2016 Author Share Posted November 20, 2016 Hey, bloody babylonians @getzel, I'll try to put together a PG - might take time though: in my game a Blender scene is loaded and then loads of objects get instanced and placed based on a json config with a bunch of coordinates. The Charecter (shooter) is then set to lookAt the camera's box and runs PickWithRay to check if the target is in 'line of sight'. Maybe here I'm doing something fishy? @Wingnut, a cleaner solution would be an all-penetrating ray returning an array of pickedMesh objects ordered on hit-first basis. And that would be one bloody useful feature too! getzel 1 Quote Link to comment Share on other sites More sharing options...
getzel Posted November 20, 2016 Share Posted November 20, 2016 Try first on your side to make a simple scene with basic meshes (not loaded) and check if you have the same problem. Quote a cleaner solution would be an all-penetrating ray returning an array of pickedMesh objects ordered on hit-first basis. And that would be one bloody useful feature too! Yea Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 20, 2016 Share Posted November 20, 2016 Max123... um... you didn't give many details but... could your parented-to-camera wall be see-through... because camera.minZ is set to high? (just checking). Nah, that doesn't sound correct. Target is parented to camera, not wall. hmm Yep, Max needs to build us a playground... or go searching for picking ray examples with a bloody playground search. Quote Link to comment Share on other sites More sharing options...
getzel Posted November 20, 2016 Share Posted November 20, 2016 There will be blood on this topic. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 21, 2016 Share Posted November 21, 2016 Please let me introduce: scene.multiPick and scene.multiPickWithRay: http://www.babylonjs-playground.com/#7CPS7 Have a bloody day gentlemen! max123, Wingnut and getzel 3 Quote Link to comment Share on other sites More sharing options...
getzel Posted November 21, 2016 Share Posted November 21, 2016 Great, thanks ! Quote Link to comment Share on other sites More sharing options...
max123 Posted November 22, 2016 Author Share Posted November 22, 2016 Awesome!! Quote Link to comment Share on other sites More sharing options...
getzel Posted November 24, 2016 Share Posted November 24, 2016 Hello dear friends ! Here is a PG with a ray working : http://www.babylonjs-playground.com/#1LZJEK#3 It is without predicate so it picks the first mesh. At the beginning, it touches box2 before the elements get positionned so we can wait before launching the raycast() if we need. After, wall get touched, then box2 and finally nothing once all mesh have moved away. I don't know if my math method is the best. I made a raycast2 function with another method : function raycast2(){ var vector1 = new BABYLON.Vector3(0,0,6); var vector2 = new BABYLON.Vector3(0,0,1); var ray = new BABYLON.Ray(vector1, vector2, 100); ray = BABYLON.Ray.Transform(ray, box1.getWorldMatrix()); // new method, there is an another one to create a ray var raycast = scene.pickWithRay(ray, null, false); if (raycast.hit){ console.log(raycast.pickedMesh.name); }else{ console.log('no'); } } // raycast2() ----------------- Is it possible to make a draw ray function please (to debug) ? How the Text2d works ? I can't display it. A simple example is welcome. Quote Link to comment Share on other sites More sharing options...
max123 Posted November 24, 2016 Author Share Posted November 24, 2016 Hey @getzel, nice to see I'm not alone basking in Rays of Babylon! I will check your solution when I get a minute. Meanwhile, I'll raise you - the RayLine:http://www.babylonjs-playground.com/#11NFGL#0 getzel 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.