Je ne peux pas lire la normale d'un terrain
Faire un raycast J'ai le bon résultat, le lire à partir de terraindata me donne une valeur incorrecte.
Je joins du code et des captures d'écran
in Update :
Code : Tout sélectionner
RaycastHit hit;
Ray raggio = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 posiz = new Vector3(36f, 15f, 7f);
if (Physics.Raycast(posiz + (Vector3.up*5),Vector3.down, out hit, Mathf.Infinity, MyGLB_E.layer_Terreno))
{
Terrain at = Terrain.activeTerrain;
float normalizedX, normalizedY; Vector3 normale;
hPoint = hit.point;
normalizedX = posiz.x / at.terrainData.size.x ;
normalizedY = posiz.z / at.terrainData.size.z ;
normale = at.terrainData.GetInterpolatedNormal(normalizedX, normalizedY);
hpointAngolo = at.terrainData.GetSteepness(normalizedX, normalizedY);
hString = "TERRAINDDATA:\n\rSP : " + hpointAngolo.ToString() + "\n\rUP : " + Vector3.Angle(Vector3.up,normale ).ToString() + "\n\rDW : " + Vector3.Angle(normale, Vector3.down).ToString() + "\n\rFW : " + Vector3.Angle(normale, Vector3.forward).ToString() + "\n\rBW : " + Vector3.Angle(normale, Vector3.back).ToString() + "\n\rRG : " + Vector3.Angle(normale, Vector3.right).ToString() + "\n\rLF : " + Vector3.Angle(normale, Vector3.left).ToString() + "\n\rNR : " + normale;
hN = normale;
normale = hit.normal;
hN0 = normale;
hString0 = "RAYCAST\n\rUP : " + Vector3.Angle(normale, Vector3.up).ToString() + "\n\rDW : " + Vector3.Angle(normale, Vector3.down).ToString() + "\n\rFW : " + Vector3.Angle(normale, Vector3.forward).ToString() + "\n\rBW : " + Vector3.Angle(normale, Vector3.back).ToString() + "\n\rRG : " + Vector3.Angle(normale, Vector3.right).ToString() + "\n\rLF : " + Vector3.Angle(normale, Vector3.left).ToString() + "\n\rNR : " + hit.normal;
}
Code : Tout sélectionner
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));