As the title says.. I want to get the ground height from x & z vectors.
I only know one thing .. that it has to do with RayCast nothing more.
I've searched unity forums but i didnt find what i was searching for.
Thanks for any help,
PaiN
Solved Getting GroundHeight from X & Z vectors
Discussion in 'Rust Development' started by PaiN, Nov 15, 2015.
-
Code:
private static LayerMask GROUND_MASKS = LayerMask.GetMask("Terrain", "World", "Construction"); //Credit: Wulf static Vector3 GetGroundPosition(Vector3 sourcePos) { RaycastHit hitInfo; if (Physics.Raycast(sourcePos, Vector3.down, out hitInfo, GROUND_MASKS)) { sourcePos.y = hitInfo.point.y; } sourcePos.y = Mathf.Max(sourcePos.y, TerrainMeta.HeightMap.GetHeight(sourcePos)); return sourcePos; }
-
Wulf Community Admin
-