getHeightAtCoordinates() doesn't work when using ground octrees

In this PG exemple, calling getHeightAtCoordinates() works OK if the ground is not optimized, but it returns NaN when optimize() is used on the ground:

I am missing something? Thanks in advance!

Hello and welcome to the forum!

I recall that this was addressed on the last forum. Here’s the topic:

If you would like further info on this, then reply and I’m certain you’ll get a more specific answer. The question I would have is what do you want to do with the reported height coordinates?


Thank you for your response!
I’m using it to position some meshes and sprites on the ground surface.
In the post you’ve linked to the discussion is about collisions, but I don’t use collisions in my scene. The meshes and sprites I’m using are static so I prefer to position them only once on the scene loading, so there is no need to have collision detection activated all the time.


It doesn’t matter if you’re detecting collisions or not. The issue is that to detect coordinates, you need to look at how the ray is fired in your scene and at what object (type) is used to detect the position. It appears that using the subdivisions of an octree set at 128 divisions, the ray doesn’t know where to fire (cast), so it returns a NaN value as it cannot compute.


Oh, I get it now, I use it this way:

Thank you, Galen!


@etherlind I have the same problem, but I can’t open the link you put to solve the NaN value after optimizing. The links open, but stays loading for hours.

Can you tell what was the solution?


I think the link is: