Dud Posted November 23, 2014 Share Posted November 23, 2014 Hi all, I am trying to find the intersection of a ray with a height map in order to be able to place point sprites at various locations on my height map. I have read the various forum postings on the subject and I believe I have everything set up correctly. My heightmap is 100x100 with 50 subdivisions and is called "ground". When I call scene.pickWithRay in the function below I *do* hit the ground and I do have a pickInfo object - however the pickInfo.pickedPoint object is always null. Have I made a mistake somewhere?Map.prototype.createPointSprite = function (scene, spriteManager, name, x, z) { var spritePosition = new BABYLON.Vector3(0, 10, 0); //Shoot a ray to get height of map at required sprite position var ray = new BABYLON.Ray(spritePosition, new BABYLON.Vector3(0, -1, 0)); var pickInfo = scene.pickWithRay(ray, function (item) { if (item.id == "ground") return true; }); //Only place a point sprite if our ray hit the ground if (pickInfo != null && pickInfo.pickedPoint != null) { var sprite = new BABYLON.Sprite(name, spriteManager); spritePosition.y = pickInfo.pickedPoint.y; sprite.position = spritePosition; } }; Quote Link to comment Share on other sites More sharing options...
Dud Posted November 24, 2014 Author Share Posted November 24, 2014 I think I've realised the problem - the method above is fine, but I need to ensure that the the "ground" mesh is ready before by checking mesh.isReady() before using the above function. Quote Link to comment Share on other sites More sharing options...
Carlos R Posted November 24, 2014 Share Posted November 24, 2014 Yes, the problem was solved here: http://www.html5gamedevs.com/topic/2248-retrieve-heightmap-altitude/ 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.