Get y position of the ground from given x and z [circle lines]

Hello everyone!
I made this playground where you can create a circle and move it around or change the radius
(double click to create center mesh, right click to finish)
Everthing works fine here, when the ground mesh is not rotated:
https://playground.babylonjs.com/#PYVQ5E#20

Here’s the playground with my qestion:
https://playground.babylonjs.com/#PYVQ5E#23

I’m wondering if I could use the gimo so the center mesh of the circle will always “touch” the ground. So if I move it with the yPlaneGizmo the mesh will have same y position as ground.

I used getHeightAtCoordinates but it doesn’t work in my case. Do I need to have some kind of ray from the mesh to check grounds y position? Or am I overthinking it?

getHeightAtCoordinates only works for GroundMesh, so I guess a ray is the best workaround here if you don’t want to use a GroundMesh.

Your PG does not work in 5.0, double-click does not work… Maybe it’s related to this problem as it’s related to inputs and utility layer being used in gizmos, so adding @PolygonalSun.

Yup, pg stopped working yesterday at ~1:30PM CET so I moved to 4.2.0. So I guess I’ll need to cast two rays at the same time. Upwards and downwards. Ok Thanks

@Evgeni_Popov could you look at https://playground.babylonjs.com/#PYVQ5E#26. I think I implemented this idea with rays but it works super slow. I added two rays - upwards and downwards the root - I think there’s too much calculation going on in there.

If you comment the rayHelper creation / rayHelper.show you will see it’s fast. That’s because all the rays you create are not disposed, so they fill in the scene:

You should remove the previous rayHelper before creating a new one.

1 Like

That’s a silly mistake, sorry! and thank you for your time!

It was indeed the same problem, your PG is now working in 5.0.

I think I implemented this idea with rays but it works super slow. I added two rays - upwards and downwards the root - I think there’s too much calculation going on in there.

@Evgeni_Popov I don’t get one thing from creating those rays. For centerMesh it works correctly
In the picture you can see 4 rays (2x upward and 2xdownward from centerMesh and edgeMesh)


https://playground.babylonjs.com/#PYVQ5E#36
I don’t get why edgeMesh’es rayHelper is moved sine it takes position of the edgeMesh (and even so why edgeMesh correctly sticks to the plane since ray “touches” plane in different y position)

Howerver if I make edgeMesh ray with absolute position it doen’t work correctly too. edgeMesh is slightly raised above the plane and you actually can’t move to the center. If it doesn’t sounds understandable here’s the video

It seems to work if you offset the y pick value by the root position.y value for the edge mesh (and use the absolute position):

https://playground.babylonjs.com/#PYVQ5E#38

I don’t really know why, I will leave it to you :slight_smile:

1 Like

wow, I’d never think of it, thanks!