How to find the nearest vertices in a terrain with a ray?

I need to get a square from the vertices where the beam hit, namely where I poked the mouse in terrain

if(Input.GetMouseButtonDown(0)){
  if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RayHit, Mathf.Infinity, ignoreLayerMask)){
    Debug.Log(RayHit.collider.tag); // if terrain
    Debug.Log(RayHit.point);// hit to face
// get 4 vertex from hit face ?
    }
  }

How to calculate them?
(not mesh, terrain…)

If you use a beam, why don’t you use OverlapCapsule/OverlapCube?

Also, what is the issue you’re having? If there are unwanted raycast hit results use layers

1 Like

I solved the problem in another way, just set the Terrain Width/Length and HeightMap Resolution to be the same and now they match the coordinates, now it’s easier to calculate…