I have opened a discussion on the terrain Normals, but I think that to find a concrete solution I need to understand why I have 2 different slope angles in the map.
I need to understand on the ground where the slope angle exceeds 35 degrees.
I tried using the terraindata.GetStepness function, but the result is incorrect.
Through Raycast and the Vectro3.Angle function I have a different and much more accurate result.
Since I have seen various discussions where the GetStepness function is used successfully, I don't understand why I have to have strange results.
I attach code and screenshots.
Thank you all!
Angle
ON UPDATE :
RaycastHit hit;
Ray raggio = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 posiz; // = new Vector3(36, 15f, 7);
//if (Physics.Raycast(posiz + (Vector3.up * 5), Vector3.down, out hit, Mathf.Infinity, MyGLB_E.layer_Terreno))
if (Physics.Raycast(raggio, out hit, Mathf.Infinity, MyGLB_E.layer_Terreno))
{
posiz = hit.point;
Terrain at = Terrain.activeTerrain;
float normalizedX, normalizedY; Vector3 normale;
hPoint = hit.point;
posizp = new Vector3(posiz.x, at.terrainData.GetInterpolatedHeight(posiz.x / at.terrainData.size.x, posiz.z / at.terrainData.size.z),posiz.z);
normalizedX = posizp.x / at.terrainData.size.x ;
normalizedY = posizp.z / at.terrainData.size.z ;
normale = at.terrainData.GetInterpolatedNormal(normalizedX, normalizedY);
hpointAngolo = at.terrainData.GetSteepness(normalizedX, normalizedY) ;
hString = "TERRAINDDATA (Green):
STEPNESS : " + hpointAngolo.ToString() + "
NMap : " + normale + "
AT : " + posizp;
hN = normale;
normale = hit.normal;
hN0 = normale;
hString0 = "RAYCAST (Red)
ANGLE UP : " + Vector3.Angle(normale, Vector3.up).ToString() + "
NMap : " + hit.normal + "
AT : " + hit.point;
}
ON GIZMO :
GUIStyle style = new GUIStyle(GUI.skin.label);
style.alignment = TextAnchor.MiddleLeft;
Handles.Label(hPoint, hString0 + "
" + hString, style);
Gizmos.color = Color.green;
Gizmos.DrawRay(posizp, hN * 1);
Gizmos.color = Color.red;
Gizmos.DrawRay(hPoint, hN0 * 0.5f);
question from:
https://stackoverflow.com/questions/65829131/unity3d-get-stepness-without-raycast 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…