Jump to content

Retrieve heightmap altitude


isigui
 Share

Recommended Posts

Hi, 

 

You should use a noise function to randomize the y position of your vertices. You can for example look at perlin noisehttp://en.wikipedia.org/wiki/Perlin_noisehttp://stackoverflow.com/questions/4753055/perlin-noise-generation-for-terrain).

This function returns a number that you could use to generate your bumpy ground.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 !!!

Link to comment
Share on other sites

  • 10 months later...

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

Link to comment
Share on other sites

  • 7 months later...

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? :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...