# wrong slope on terraint

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

ok, i found problem in get normal…

this is code in update :

``````		RaycastHit hit;
//Ray raggio = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 posiz = new Vector3(36.271f, 11f, 6.72780f);
if (Physics.Raycast(posiz + (Vector3.up*5),Vector3.down, out hit, Mathf.Infinity, MyGLB_E.layer_Terreno))
{

float normalizedX, normalizedY; Vector3 normale;
//indicatore.transform.position = hit.point;
hPoint = hit.point;
normalizedX = posiz.x / terrainMesh.terrainData.size.x;
normalizedY =  posiz.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(Vector3.up,normale ).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() + "
\rNR : " + normale;
hN = normale;
normale = hit.normal;
hN0 = normale;
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() + "
\rNR : " + hit.normal;

``````		}
``````

this is code in gizmo :

``````		GUIStyle style = new GUIStyle(GUI.skin.label);
style.alignment = TextAnchor.MiddleLeft;
Handles.Label(hPoint, hString0, style);
Handles.Label(hPoint + Vector3.right, hString, style);
Gizmos.color = Color.green;
Gizmos.DrawLine(hPoint,hPoint + ( hN * 1));
Gizmos.color = Color.red;
Gizmos.DrawLine(hPoint, hPoint + (hN0 * 1));
``````

why normal of terraindata is different to normal of raycast?