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.
Find ground level coordinates?
Discussion in 'Rust Discussion' started by ThunderZ, Feb 21, 2017.
-
maybe doing a raycast downards from somewhere that you know will be above the terrain & getting the location from its hits
-
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; }