1. Is there any possible way to detect ground level coordinates?

    X, (Y), Z??

    I'm trying to make sure things spawn above the ground but not in the air and not below ground.
     
  2. maybe doing a raycast downards from somewhere that you know will be above the terrain & getting the location from its hits
     
  3. Wulf

    Wulf Community Admin

    Code:
            static Vector3 GetGroundPosition(Vector3 sourcePos)
            {
                RaycastHit hitInfo;
                var groundLayer = LayerMask.GetMask("Terrain", "World", "Construction");
                if (Physics.Raycast(sourcePos, Vector3.down, out hitInfo, groundLayer)) sourcePos.y = hitInfo.point.y;
                sourcePos.y = Mathf.Max(sourcePos.y, TerrainMeta.HeightMap.GetHeight(sourcePos));
                return sourcePos;
            }