AndyBeaulieu Posted November 30, 2013 Share Posted November 30, 2013 I have read the basic tutorial for collision detection here - http://github.com/BabylonJS/Babylon.js/wiki/10-Object-collisions But what I want to do is shoot a ray straight down in the Y from a one mesh and see where it intersects with a second mesh. The first mesh is a simple sphere, but I want to snap it to a second mesh that is has vertices data (elevations). So in this video here - http://www.youtube.com/watch?v=0S08faz1JpE&feature=youtu.be... you will see a bunch of yellow spheres that appear above mesh tiles. I would like to snap those to the mesh tiles that are directly below them. What is the best way to do this? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 30, 2013 Share Posted November 30, 2013 Hello, you can use scene.pickWithRay(ray, predicate) ray is a...ray (BABYLON.Ray) and predicate can be null or a function(mesh) returning true or false if you want to test against specific mesh pickWithRay will return a pickInfo object with pickedPoint property isigui 1 Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted December 1, 2013 Author Share Posted December 1, 2013 Sorry, I am not understanding pickWithRay... Here is a simple jsbin - http://jsbin.com/eHEMaLUJ/2/edit?html,output The sample has a sphere located at (0,20,0) and a plane located at (0,0,0). I want to find the intersection point of a ray shot from the sphere straight down the Y, to the plane. So I do: new BABYLON.Ray(sphere.position, new BABYLON.Vector3(0, -500, 0)); I would expect the pickedPoint to be equal to where the ray intersects plane, but instead I get pickedPoint = (0, 19.96, 0). Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 1, 2013 Share Posted December 1, 2013 The direction of the ray should be normalized. if you use new BABYLON.Ray(sphere.position, new BABYLON.Vector3(0, -1, 0)) it should work:) volter9 1 Quote Link to comment Share on other sites More sharing options...
AndyBeaulieu Posted December 1, 2013 Author Share Posted December 1, 2013 Thanks, that was too easy I updated the jsbin if anyone needs a sample - http://jsbin.com/ubAwapU/3/edit?html,output Thanks! 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.