UNITY3D:在没有光线投射的情况下获得步进

问题描述

我已经开始讨论地形法线,但我认为要找到具体的解决方案,我需要了解为什么我在地图中有 2 个不同的坡度角。 我需要在地面上了解坡度角超过35度的地方。 我尝试使用terraindata.GetStepness 函数,但结果不正确。 通过 Raycast 和 Vectro3.Angle 函数,我得到了不同且更准确的结果。 由于看到了各种关于成功使用GetStepness函数的讨论,我不明白为什么我必须有奇怪的结果。 我附上代码和截图。 谢谢你们! Angle

更新中:

        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,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):\n\rSTEPnesS : " +  hpointAnGolo.ToString()  + "\n\rNMap : " +  normale + "\n\rAT : " + posizp;
        hN = normale;
        normale = hit.normal;
        hN0 = normale;
        hString0 = "RAYCAST (Red)\n\rANGLE UP : " +  Vector3.Angle(normale,Vector3.up).ToString() +  "\n\rNMap : " + hit.normal + "\n\rAT : " + hit.point;
    }

在 GIZMO 上:

        GUIStyle style = new GUIStyle(GUI.skin.label);
    style.alignment = TextAnchor.MiddleLeft;
    Handles.Label(hPoint,hString0 + "\n\r\n\r" + hString,style);
    Gizmos.color = Color.green;
    Gizmos.DrawRay(posizp,hN * 1);
    Gizmos.color = Color.red;
    Gizmos.DrawRay(hPoint,hN0 * 0.5f);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)