isigui Posted November 21, 2013 Share Posted November 21, 2013 Hello,I use the function CreateGroundFromHeightMap in order to generate a bumpy ground. How can I retrieve the y value giving a x and z position ? Thanks for your feedback ! Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 21, 2013 Share Posted November 21, 2013 Hi, You should use a noise function to randomize the y position of your vertices. You can for example look at perlin noise : http://en.wikipedia.org/wiki/Perlin_noise, http://stackoverflow.com/questions/4753055/perlin-noise-generation-for-terrain).This function returns a number that you could use to generate your bumpy ground. Quote Link to comment Share on other sites More sharing options...
isigui Posted November 21, 2013 Author Share Posted November 21, 2013 Hi,thanks for you reply.Actually, I already got a heightmap that I use to generate my ground.I use the function CreateGroundFromHeightMap that helps me to generate my ground and returns the mesh of the plane.I'd like that my character follows the topology of the ground ans stops when the slope is too large.I thought I could do that comparing the y altitude of my character and the y altitude of my Ground...that's why I'd like to retrieve the y value of the ground giving a x,z position. Quote Link to comment Share on other sites More sharing options...
reddozen Posted November 21, 2013 Share Posted November 21, 2013 If you have a character running around, and you're using collision detections then you could just use the Y of your character. That would be a useful function though to get the Y value from known XZ. Kind of necessary for a drag and drop if you want things to fall to the ground. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 21, 2013 Share Posted November 21, 2013 You can also create a BABYLON.Ray heading to negative Y and use mesh.intersects(ray) to get the intersection between the ray and your ground. Carlos R, isigui and WiMantis 3 Quote Link to comment Share on other sites More sharing options...
isigui Posted November 22, 2013 Author Share Posted November 22, 2013 Thank you, using the BABYLON.Ray object works fine ! My character follow the ground as a chewingum stuck to a shoe ! ;o)))Do you think I can you use Ray also to detect collision with walls ?The "collision" ray direction will have the same direction as my character and its origin will be in the center of the character... ? Thanks again !!! Quote Link to comment Share on other sites More sharing options...
reddozen Posted November 22, 2013 Share Posted November 22, 2013 I think the only problem you would have is objects that you don't what to collide with. Like if you allowed clipping with certain bushes. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 22, 2013 Share Posted November 22, 2013 It will also work. You jusr have to select meshes you want to test with. Quote Link to comment Share on other sites More sharing options...
Carlos R Posted October 20, 2014 Share Posted October 20, 2014 Hi guys, i'm trying to retrieve the altitude of a heightmap but nothing happends. Here i have an example using a simple groundMesh: http://www.babylonjs.com/playground/#24LCDU#1 ,You can see that it works well, at any given coordinate (x,z), i could retrive the 'y' value. But not with CreateGroundFromHeightMap, not anymore . Check this example: http://uvshop.co/babylonjs/problema/ Also, i try to use 'ground.intersects(rayo, false).pickedPoint' but nothing happends. What can i do? Thanks in advance, Carlos-R Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 20, 2014 Share Posted October 20, 2014 Could you create a playground example? (far easier for me to debug:)) Quote Link to comment Share on other sites More sharing options...
Carlos R Posted October 21, 2014 Share Posted October 21, 2014 Of course, http://www.babylonjs.com/playground/#SLHC2 Line 40. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 21, 2014 Share Posted October 21, 2014 Ok that's expected. When you launch the scene.pick, the mesh is not ready yet (texture still loading), you have to do that when the mesh.isReady() === true Carlos R 1 Quote Link to comment Share on other sites More sharing options...
Carlos R Posted October 22, 2014 Share Posted October 22, 2014 Hey thanks, it works. Quote Link to comment Share on other sites More sharing options...
tr00n Posted May 30, 2015 Share Posted May 30, 2015 Hi guys,I've been trying to follow the above instructions but I have trouble getting it to work. I have a heightmap terrain and I basically wish to get the Y position of a ray intersection. My basic setup is something like the following:var createScene = function () { return scene; } var scene = createScene();engine.runRenderLoop(function () {..}The code that I use to retrieve the Y position is the following:if(ground.isReady()===true){var pickInfo = scene.pickWithRay(ray, function (item) { if (item.id == "ground") return true;}); console.log(pickInfo)}When I put this in the createScene() function it seems as if the ground.isReady() never gets set to TRUE. The code inside the IF never gets run. However if I put the code into the engine.runRenderLoop it works just fine. The position is retrievable. How can I get the isReady() function to work as intended within the creteScene()? Am I missing something obvious? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 1, 2015 Share Posted June 1, 2015 You can use scene.executeWhenready(func) mickeyren 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.