Hi everyone,
I would like to understand in certain points of the terrain what its slope angle is, but I cannot understand the results
I attach code (in update function) , screenshots and results
RaycastHit hit;
Ray raggio = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(raggio, out hit, Mathf.Infinity, MyGLB_E.layer_Terreno))
{
float normalizedX, normalizedY; Vector3 normale;
indicatore.transform.position = hit.point;
hPoint = hit.point;
normalizedX = hit.point.x / terrainMesh.terrainData.size.x;
normalizedY = hit.point.z / terrainMesh.terrainData.size.z;
normale = terrainMesh.GetComponent<TerrainCollider>().terrainData.GetInterpolatedNormal(normalizedX, normalizedY);
hpointAngolo = terrainMesh.GetComponent<TerrainCollider>().terrainData.GetSteepness(normalizedX, normalizedY);
hString = "TERRAINDDATA:
\rSP : " + hpointAngolo.ToString() + "
\rUP : " + Vector3.Angle(normale, Vector3.up).ToString() + "
\rDW : " + Vector3.Angle(normale, Vector3.down).ToString() + "
\rFW : " + Vector3.Angle(normale, Vector3.forward).ToString() + "
\rBW : " + Vector3.Angle(normale, Vector3.back).ToString() + "
\rRG : " + Vector3.Angle(normale, Vector3.right).ToString() + "
\rLF : " + Vector3.Angle(normale, Vector3.left).ToString();
normale = hit.normal;
hString0 = "RAYCAST
\rUP : " + Vector3.Angle(normale, Vector3.up).ToString() + "
\rDW : " + Vector3.Angle(normale, Vector3.down).ToString() + "
\rFW : " + Vector3.Angle(normale, Vector3.forward).ToString() + "
\rBW : " + Vector3.Angle(normale, Vector3.back).ToString() + "
\rRG : " + Vector3.Angle(normale, Vector3.right).ToString() + "
\rLF : " + Vector3.Angle(normale, Vector3.left).ToString();
//Debug.Log(hString0 + hString);
}
Result:
X Point left :
RAYCAST
UP : 0
DW : 180
FW : 90
BW : 90
RG : 90
LF : 90
TERRAINDDATA:
SP : 0,5237671
UP : 0,5237671
DW : 179,4762
FW : 89,62936
BW : 90,37065
RG : 89,62936
LF : 90,37065
X Point Center
RAYCAST
UP : 49,58921
DW : 130,4108
FW : 92,9032
BW : 87,0968
RG : 139,4404
LF : 40,55961
TERRAINDDATA:
SP : 13,1032
UP : 13,10318
DW : 166,8968
FW : 90,73031
BW : 89,2697
RG : 103,0821
LF : 76,9179
X Point Right
RAYCAST
UP : 50,68999
DW : 129,31
FW : 92,8371
BW : 87,1629
RG : 39,45312
LF : 140,5469
TERRAINDDATA:
SP : 4,573589
UP : 4,573675
DW : 175,4263
FW : 87,25487
BW : 92,74513
RG : 93,65543
LF : 86,34457
Raycast is more precise of terraindata… but both are imprecise
Tanks for your help, sorry for the english but i don’t speak it